The 5.7 branch of Magnolia reached End-of-Life on December 31, 2023, as specified in our End-of-life policy. This means the 5.7 branch is no longer maintained or supported. Please upgrade to the latest Magnolia release. By upgrading, you will get the latest release of Magnolia featuring significant improvements to the author and developer experience. For a successful upgrade, please consult our Magnolia 6.2 documentation. If you need help, please contact info@magnolia-cms.com.

navfn templating functions allow you to create navigation for your site. There are methods to access standard pages and also content stored in apps and rendered on virtual pages. The navfn templating function library is included in the MTE module.

Returns the highest ancestor page of type mgnl:page for the provided content - which is the root page.

ContentMap rootPage(ContentMap content)

content

required

The node whose ancestors you want to get.

ContentMap

navfn.rootPage(content)

[#assign navigationRootPage = navfn.rootPage(content)!]

Returns the ancestor of the provided content at the specified depth if the ancestor is of type mgnl:page.

ContentMap ancestorPageAtLevel(ContentMap content, int depth)

content

required

The node whose ancestors you want to get.

depth

required

The page depth.

An ancestor of depth x is the page that is x levels down along the path from the root page to this page. e.g. depth == 1 would return the root page of this page, depth == 2 would return the child page of the root page to this page, etc.

ContentMap

navfn.ancestorPageAtLevel(content, depth)

[#assign subNavigationRootPage = navfn.ancestorPageAtLevel(content, 2)!]

Returns the list of child nodes of type mgnl:page which aren't hidden in navigation of the the provided page as a list of content maps.

List<ContentMap> navItems(ContentMap page)

page

required

The page whose child pages you want to get.

List<ContentMap>

navfn.navItems(page)

 <!-- render links to all pages on "level 1" -->
[#assign navParentItem = navfn.rootPage(content)!]
[#if navParentItem??]
  [#assign navItems = navfn.navItems(navParentItem)]
  [#list navItems as navItem]
      <a href="${cmsfn.link(navItem)!}">${navItem.navigationTitle!navItem.title!navItem.@name}</a> |
  [/#list]
[/#if]

Returns the list of child nodes with specific node type which aren't hidden in navigation from a defined parent as a list of content maps. The workspace and parent path define the location of the parent. Use this method to render navigations for content stored in content apps on workspaces distinct from website.

List<ContentMap> navItemsFromApp(String workspace, String parentPath, String nodeType)

workspace

required

The workspace of the parent node.

parentPath

required

The path of the parent node whose children you want to get.

nodeType

required

The node type of the children you want to get.

List<ContentMap>

navfn.navItemsFromApp(workspace, parentPath, nodeType)

[#assign navContentItems = navfn.navItemsFromApp("contacts", "/", "mgnl:contact")] 
[#list navContentItems as navItem]
	[#-- do something with the navItem here  --]
[/#list]

Checks whether the given page has the specified template.

boolean hasTemplate(ContentMap page, String template)

page

required

The page whose template you want to check.

template

required

The template to check for.

boolean

navfn.hasTemplate(page, template)

[#if navfn.hasTemplate(content, "mtk:pages/contacts")]
  [#-- do something here --]
[/#if]

Checks whether the given page has the specified template type.

boolean hasTemplateType(ContentMap page, String templateType)

page

required

The page whose template you want to check.

templateType

required

The template type to check for.

boolean

navfn.hasTemplateType(ContentMap page, String templateType)

[#if navfn.hasTemplateType(content, "section")]
  [#-- do something here --]
[/#if]

Checks whether the given page has the specified template subtype.

boolean hasTemplateSubtype(ContentMap page, String templateSubtype)

page

required

The page whose template you want to check.

templateSubType

required

The sub-template type to check for.

boolean

navfn.hasTemplateSubtype(page, templateSubtype)

[#if navfn.hasTemplateSubtype(navItem, "contactsOverview")]
	[#-- do something here --]
[/#if]

Returns a page URL with a selector (delimited by the ~ [tilde] character) identifying the content to be rendered. This relies on Magnolia's selector mechanismfor example  https://demopublic.magnolia-cms.com/tour-type~beach~.html

String linkWithSelector(ContentMap page, ContentMap content)

page

required

The page whose URL you want to get.

content

required

The content from the content app. For example contact, tour, etc.

String

navfn.linkWithSelector(page, content)

<a href="${navfn.linkWithSelector(page, navContentItem)!"#"}">${navContentItem.lastName!navContentItem.@name}</a>

Returns a page url with a parameter identifying the content to be rendered.
A link of this type is produced http://mysite/mypage.html?parameterName=mycontent where 'mypage' is the node name of the target page, 'mycontent' the node name of the content.

String linkWithParameter(ContentMap page, ContentMap content)

String linkWithParameter(ContentMap page, ContentMap content, String parameterName)

page

required

The page whose URL you want to get.

content

required

The content from the content app. For example contact, tour, etc.

parameterName

optional, default is <workspace-name>

The parameter name.

String

navfn.linkWithParameter(page, content)

<a href="${navfn.linkWithParameter(page, navContentItem)!"#"}">${navContentItem.lastName!navContentItem.@name}</a>

navfn.linkWithParameter(page, content, parameterName)

<a href="${navfn.linkWithParameter(page, navContentItem, "contacts")!"#"}">${navContentItem.lastName!navContentItem.@name}</a>

Returns a URL for the provided content.

String link(ContentMap content)

content

required

The content for which you want to get URL.

String

navfn.link(content)

<a href="${navfn.link(navigationItem)!"#"}">${navigationItem.navigationTitle!navigationItem.title!navigationItem.@name}</a>

Checks whether navigation item is the currently displayed content.

boolean isActive(ContentMap content, ContentMap navigationItem)

content

required

The current content node (page/area/component).

navigationItem

required

The navigation item.

boolean

navfn.isActive(content, navigationItem)

[#if navfn.isActive(content, navItem)]
	...
[/#if]

Checks whether navigation item is the ancestor of the current page.

boolean isOpen(ContentMap content, ContentMap navigationItem)

content

required

The current content node.

navigationItem

required

The navigation item.

boolean

navfn.isOpen(content, navigationItem)

[#if navfn.isOpen(content, navItem)]
	...
[/#if]

Checks whether the given content should be hidden in navigation. The hideInNav property of the given content is used.

boolean isHiddenInNav(ContentMap content)

content

required

The content node.

boolean 

navfn.isHiddenInNav(content)

[#if !navfn.isHiddenInNav(navItem)]
   ...
[/#if] 

Checks whether the given content should not be hidden in navigation. The hideInNav property of the given content is used.

boolean isNotHiddenInNav(ContentMap content)

content

required

The content node.

boolean

navfn.isNotHiddenInNav(content)

[#if navfn.isNotHiddenInNav(navigationItem)]
	...
[/#if]

This is small helper method which checks if a given property is true or false. The method is needed because in a FreeMarker template you don't know if a property is stored as boolean or a string or if it exists at all.

The method avoids using checks like:

[#if navItem.showInNav?has_content &amp;&amp; navItem.showInNav?string == "true"]

boolean isTrue(ContentMap content, String propertyName)

content

required

The content node.

propertyName

required

The property name.

boolean

navfn.isTrue(content, propertyName)

[#if navfn.isTrue(navItem, "showInNav")]
	...
[/#if]