Use _index_ Sitemap Items
Info: The
_index_sitemap item feature is available starting from Hippo CMS 11.2.0.
Overview
The _index_ sitemap item allows you to map URLs to a default document or folder. If the default document or folder does not exist, the request falls back to the parent sitemap item's content. This mechanism provides flexible handling of folder and document rendering in your site's URL structure.
When to Use
Use _index_ sitemap items when you need to:
- Render a default document (such as an introduction or overview) when a user navigates to a folder URL.
- Fall back to rendering a folder listing if the default document is not present.
- Support flexible URL mapping that adapts to the presence or absence of specific documents within folders.
Background
With sitemap wildcard matchers, you can map parts of your website's URL space directly to corresponding sections in the content repository. This mapping can target both documents and folders. When a URL maps to a document, the document content is rendered. When a URL maps to a folder, you have options such as rendering a list of documents in the folder or displaying a default document.
The _index_ sitemap item extends this approach. You can add an _index_ child sitemap item to explicit or _default_ sitemap items. When a request matches a sitemap item with an _index_ child, the system attempts to resolve the request to the content path defined in the _index_ sitemap item. If that path does not exist, the request falls back to the content path of the originally matched sitemap item.
For a detailed explanation of how _index_ sitemap items work, see SiteMapItem Matching (section SiteMapItem _index_).
Example
This example uses a project created with the Bloomreach Content Maven archetype and includes the "Simple Content" feature.
By default, the "Simple Content" feature provides the following sitemap structure:
/hst:myproject/hst:configurations/myproject/hst:sitemap: /content: hst:componentconfigurationid: hst:pages/contentlist hst:relativecontentpath: content /_any_: hst:componentconfigurationid: hst:pages/contentlist hst:relativecontentpath: ${parent}/${1} /_any_.html: hst:componentconfigurationid: hst:pages/contentpage hst:relativecontentpath: ${parent}/${1}
- The
/content/_any_sitemap item maps to folders and renders thecontentlistpage, which displays a list of documents in the folder and its subfolders. For example, the URLhttp://localhost:8080/site/content/artists/maps to the foldercontent/artistsand renders its document list. - The
/content/_any_.htmlsitemap item maps to documents and renders thecontentpage, displaying the document's content. For example,http://localhost:8080/site/content/artists/sculptors/rodin.htmlmaps to the documentcontent/artists/sculptors/rodin.
To render a default document (such as introduction) when a folder URL is accessed, update the sitemap to use _index_ sitemap items. If the default document does not exist, the system falls back to rendering the folder's document list.
Refactored Sitemap Structure
/hst:myproject/hst:configurations/myproject/hst:sitemap: /content: hst:componentconfigurationid: hst:pages/contentlist hst:relativecontentpath: news /_default_: hst:componentconfigurationid: hst:pages/contentlist hst:relativecontentpath: ${parent}/${1} /_default_: hst:componentconfigurationid: hst:pages/contentlist hst:relativecontentpath: ${parent}/${2} /_any_: hst:componentconfigurationid: hst:pages/contentlist hst:relativecontentpath: ${parent}/${3} /_any_.html: hst:componentconfigurationid: hst:pages/contentpage hst:relativecontentpath: ${parent}/${3} /_index_: hst:componentconfigurationid: hst:pages/contentpage hst:relativecontentpath: ${parent}/introduction /_default_.html: hst:componentconfigurationid: hst:pages/contentpage hst:relativecontentpath: ${parent}/${2} /_index_: hst:componentconfigurationid: hst:pages/contentpage hst:relativecontentpath: ${parent}/introduction /_default_.html: hst:componentconfigurationid: hst:pages/contentpage hst:relativecontentpath: ${parent}/${1} /_index_: hst:componentconfigurationid: hst:pages/contentpage hst:relativecontentpath: ${parent}/introduction
Key changes:
_index_sitemap items cannot be children of_any_sitemap items. The second and third URL segments aftercontentare now matched by_default_sitemap items._any_sitemap items match any remaining URL segments after the first three matched bycontent/_default_/_default_._index_sitemap items are added as children ofcontent,content/_default_, andcontent/_default_/_default_.- Each
_index_sitemap item maps to${parent}/introduction, targeting a document namedintroductionin the parent folder.
Resulting Behavior
- The
content,content/_default_, andcontent/_default_/_default_sitemap items map to folders. Their_index_child checks for anintroductiondocument in the mapped folder. If it exists, the system renders it using thecontentpagepage. - If the folder does not contain an
introductiondocument, the system falls back to the parent sitemap item and renders the folder's document list using thecontentlistpage.
Example Content Structure
/content/documents/myproject: /content: jcr:primaryType: hippostd:folder /artists: jcr:primaryType: hippostd:folder /introduction: jcr:primaryType: hippo:handle /sculptors: jcr:primaryType: hippostd:folder /rodin: jcr:primaryType: hippo:handle /brancusi: jcr:primaryType: hippo:handle /introduction: jcr:primaryType: hippo:handle
- The URL
http://localhost:8080/site/content/artists/maps to the foldercontent/artists. Becausecontent/artists/introductionexists, its content is rendered using thecontentpagepage. - The URL
http://localhost:8080/site/content/artists/sculptorsmaps to the foldercontent/artists/sculptors. Since there is nointroductiondocument in that folder, the system renders a list of documents in the folder using thecontentlistpage.