@Singleton public class NavigationTemplatingFunctions extends Object
ContentMap
(or a collection of it) which is more easily accessible in template scripts via . (dot) notation.
Functions are exposed in templates as navfn
.
navigation.ftl
macros or the documentation at
https://documentation.magnolia-cms.com/display/DOCS55/navfn.Modifier and Type | Field and Description |
---|---|
static String |
HIDE_IN_NAVIGATION_PROPERTY_NAME |
Constructor and Description |
---|
NavigationTemplatingFunctions(info.magnolia.templating.functions.TemplatingFunctions templatingFunctions) |
Modifier and Type | Method and Description |
---|---|
info.magnolia.jcr.util.ContentMap |
ancestorPageAtLevel(info.magnolia.jcr.util.ContentMap page,
int depth)
Returns the ancestor of the provided page at the specified depth only if the ancestor has node type
"mgnl:page" . |
boolean |
hasTemplate(info.magnolia.jcr.util.ContentMap page,
String template)
Checks whether the given page has the specified template.
|
boolean |
hasTemplateSubtype(info.magnolia.jcr.util.ContentMap page,
String templateSubtype)
Checks whether the given page has the specified template subtype.
|
boolean |
hasTemplateType(info.magnolia.jcr.util.ContentMap page,
String templateType)
Checks whether the given page has the specified template type.
|
boolean |
isActive(info.magnolia.jcr.util.ContentMap content,
info.magnolia.jcr.util.ContentMap navigationItem)
Checks whether navigation item is the currently displayed content.
|
boolean |
isHiddenInNav(info.magnolia.jcr.util.ContentMap content)
Checks whether the given content is hidden in navigation.
|
boolean |
isNotHiddenInNav(info.magnolia.jcr.util.ContentMap content)
Negates
isHiddenInNav(ContentMap) . |
boolean |
isOpen(info.magnolia.jcr.util.ContentMap content,
info.magnolia.jcr.util.ContentMap navigationItem)
Checks whether navigation item is the ancestor of current content.
|
boolean |
isTrue(info.magnolia.jcr.util.ContentMap content,
String propertyName)
A helper method checking whether a given property is true or false.
|
String |
link(info.magnolia.jcr.util.ContentMap content)
Returns a url for the provided content.
|
String |
linkWithParameter(info.magnolia.jcr.util.ContentMap targetPage,
info.magnolia.jcr.util.ContentMap content)
Returns a page url with a parameter identifying the content to be rendered.
|
String |
linkWithParameter(info.magnolia.jcr.util.ContentMap targetPage,
info.magnolia.jcr.util.ContentMap content,
String parameterName)
Returns a page url with a parameter identifying the content to be rendered.
|
String |
linkWithSelector(info.magnolia.jcr.util.ContentMap targetPage,
info.magnolia.jcr.util.ContentMap content)
Returns a page url with a selector (delimited by the
~ [tilde] character) identifying the
content to be rendered. |
List<info.magnolia.jcr.util.ContentMap> |
navItems(info.magnolia.jcr.util.ContentMap page)
Returns a list of child nodes for the
"mgnl:page" node type
of the provided page. |
List<info.magnolia.jcr.util.ContentMap> |
navItemsFromApp(String workspace,
String parentPath,
String nodeType)
Returns a list of child nodes for a given parent with a given node type in a given workspace.
|
info.magnolia.jcr.util.ContentMap |
rootPage(info.magnolia.jcr.util.ContentMap page)
Returns the furthest ancestor with node type
"mgnl:page"
of the provided page. |
public static final String HIDE_IN_NAVIGATION_PROPERTY_NAME
@Inject public NavigationTemplatingFunctions(info.magnolia.templating.functions.TemplatingFunctions templatingFunctions)
public info.magnolia.jcr.util.ContentMap rootPage(info.magnolia.jcr.util.ContentMap page) throws javax.jcr.RepositoryException
"mgnl:page"
of the provided page.
Useful to find the root or home page of your current page.
javax.jcr.RepositoryException
NodeTypes.Page.NAME
public info.magnolia.jcr.util.ContentMap ancestorPageAtLevel(info.magnolia.jcr.util.ContentMap page, int depth) throws javax.jcr.RepositoryException
"mgnl:page"
.
E.g. depth == 1
would return the root page to this page, depth == 2
would return the
child page of the root page, etc.
page
- The page against which depth is calculated.depth
- An ancestor of depth x is the page that is x levels down along the path from the root to this page.javax.jcr.RepositoryException
public List<info.magnolia.jcr.util.ContentMap> navItems(info.magnolia.jcr.util.ContentMap page) throws javax.jcr.RepositoryException
"mgnl:page"
node type
of the provided page.
Only non hidden in navigation nodes are returned. A node hidden in navigation is one which has
"hideInNav"
property set to true
.
javax.jcr.RepositoryException
public List<info.magnolia.jcr.util.ContentMap> navItemsFromApp(String workspace, String parentPath, String nodeType) throws javax.jcr.RepositoryException
"hideInNav"
property set to true
.
A usage sample from travel-demo's navigation.ftl
macro follows. Here tour types are retrieved
from the category
workspace and a link to a page capable of displaying such items is then created
with linkWithSelector(ContentMap, ContentMap)
.
[#assign navContentItems = navfn.navItemsFromApp("category", "/tour-types", "mgnl:category")] [#list navContentItems as navContentItem] <li><a href="${navfn.linkWithSelector(navItem, navContentItem)!"#"}">${navContentItem.displayName!navContentItem.@name}</a></li> [/#list]
workspace
- the JCR workspace for the content appparentPath
- the path to the node whose children we want to retrieve in order to build navigation itemsnodeType
- the JCR node type for the content app workspacejavax.jcr.RepositoryException
linkWithSelector(ContentMap, ContentMap)
public boolean hasTemplate(info.magnolia.jcr.util.ContentMap page, String template) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
public boolean hasTemplateType(info.magnolia.jcr.util.ContentMap page, String templateType) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
public boolean hasTemplateSubtype(info.magnolia.jcr.util.ContentMap page, String templateSubtype) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
public String linkWithSelector(info.magnolia.jcr.util.ContentMap targetPage, info.magnolia.jcr.util.ContentMap content) throws javax.jcr.RepositoryException
~
[tilde] character) identifying the
content to be rendered.
This relies on Magnolia's selector mechanism.
A link of this type is produced http://mysite/mypage~mycontent~.html
where 'mypage' is the node
name of the target page and 'mycontent' the node name of the content.
javax.jcr.RepositoryException
navItemsFromApp(String, String, String)
public String linkWithParameter(info.magnolia.jcr.util.ContentMap targetPage, info.magnolia.jcr.util.ContentMap content) throws javax.jcr.RepositoryException
A link of this type is produced http://mysite/mypage.html?workspaceName=contentNodeName
where
'mypage' is the node name of the target page, 'contentNodeName' the node name of the content and 'workspaceName'
is where the latter comes from'.
javax.jcr.RepositoryException
public String linkWithParameter(info.magnolia.jcr.util.ContentMap targetPage, info.magnolia.jcr.util.ContentMap content, String parameterName) throws javax.jcr.RepositoryException
A link of this type is produced http://mysite/mypage.html?parameterName=contentNodeName
where
'mypage' is the node name of the target page, 'contentNodeName' the node name of the content.
javax.jcr.RepositoryException
linkWithParameter(ContentMap, ContentMap)
public String link(info.magnolia.jcr.util.ContentMap content) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
public boolean isActive(info.magnolia.jcr.util.ContentMap content, info.magnolia.jcr.util.ContentMap navigationItem) throws javax.jcr.RepositoryException
content
- can be either a node from a content app or page proper.javax.jcr.RepositoryException
public boolean isOpen(info.magnolia.jcr.util.ContentMap content, info.magnolia.jcr.util.ContentMap navigationItem) throws javax.jcr.RepositoryException
content
- can be either a node from a content app or page proper.javax.jcr.RepositoryException
public boolean isHiddenInNav(info.magnolia.jcr.util.ContentMap content) throws javax.jcr.RepositoryException
A node hidden in navigation is one which has "hideInNav"
property set to true
.
javax.jcr.RepositoryException
public boolean isNotHiddenInNav(info.magnolia.jcr.util.ContentMap content) throws javax.jcr.RepositoryException
isHiddenInNav(ContentMap)
.javax.jcr.RepositoryException
public boolean isTrue(info.magnolia.jcr.util.ContentMap content, String propertyName) throws javax.jcr.RepositoryException
[#if child.showInNav?has_content && child.showInNav?string == "true"]
.javax.jcr.RepositoryException
Copyright © 2018 Magnolia International Ltd.. All rights reserved.