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.

Accessing ancestors

Getting the root page

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

Method signature

Argument

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.

Getting child nodes by workspace, path and node type

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.

Returns

Usage

Accessing URLs

Getting a page URL with a selector

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

Method signature

String linkWithSelector(ContentMap page, ContentMap content)

Argument

page

required

The page whose URL you want to get.

content

required

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

Returns

String

Usage

Getting a page URL with a parameter

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.

Returns

Usage

Checking if content should be hidden in navigation

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

Method signature

boolean isHiddenInNav(ContentMap content)

Argument

content

required

The content node.

Returns

boolean

Usage

navfn.isHiddenInNav(content)

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

Checking if content should not be hidden in navigation

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

Method signature

boolean isNotHiddenInNav(ContentMap content)

Argument

content

required

The content node.

Returns

boolean

Usage

navfn.isNotHiddenInNav(content)

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

Checking for property values

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.