catfn templating functions get content by category. For example,
you can retrieve all pages tagged with travel. Categories are
typically rendered as links on the website. They help visitors
discover related content.
Access categorized content
Categories of node
Returns all category nodes linked to a given node.
This page belongs to the categories:
[#assign allCategories = catfn.getCategories(cmsfn.asJCRNode(content))]
[#list cmsfn.asContentMapList(allCategories) as cat ]
${cat.name},
[/#list]
Copy
Related categories
Gets all pages with categories related to a given category. Related categories are referenced in the
Categories app.
A collection of node items marked with related categories.
Usage
catfn.getRelatedCategories(name)
[#assign myCategory = "biochemistry"]
[#assign relatedCategories = catfn.getRelatedCategories(myCategory)!]
[#if relatedCategories?? && relatedCategories?size>0]
${myCategory} has the following related categories:<br/>
[#list relatedCategories as cat ]
${cat.name}
[#if cat_has_next], [/#if]
[/#list]
[#else]
${myCategory} has no related categories
[/#if]
Copy
Content for given category
Gets a collection of content node items for a given category.
This function returns content only from the website workspace.
It does not work with other workspaces.
If you need to get categorized content from another workspace, write a custom model.
Root node under which you want to look for content (for example, the root
page of a site).
name
required
Category name.
Returns
Collection<Node>
A collection of node items assigned the given category.
Usage
catfn.getContentByCategory(node, name)
Aggregating content for a certain category which is applied to page nodes (start node is root node)<br/>
The following pages are tagged with category "sports":
[#assign rootPage = cmsfn.asJCRNode(cmsfn.root(content, "mgnl:page"))!]
[#assign sportsContent = catfn.getContentByCategory(rootPage, "sports")]
[#if sportsContent??]
[#list sportsContent as catNode ]
[#if catNode.isNodeType("mgnl:page")]
[#assign link=cmsfn.link(catNode)]
[#assign title=cmsfn.asContentMap(catNode).title!catNode.getName()]
<a href="${link}">${title}</a><br/>
[/#if]
[/#list]
[/#if]
Copy
Nodes by category identifier
Performs a JCR query call in the website workspace to get all nodes
with a given category identifier under a specified page path. The method
does not filter for a certain node type. If required, you have to filter
for node types when iterating over the list.
[#assign frisbeeCatUuid = "32708be2-6c62-4cca-8eb5-d95e9261011f"]
[#assign categorizedNodes = catfn.getContentByCategoryIdentifier("/", frisbeeCatUuid)]
[#if categorizedNodes?? && categorizedNodes?size>0]
Our website contains some pages about "frisbee":<br/>
[#list categorizedNodes as node ]
[#if node.isNodeType("mgnl:page")]
[#assign contentMap = cmsfn.asContentMap(node)]
${contentMap.title!node.getName()}<br/>
[/#if]
[/#list]
[#else]
No pages found related to the category with the uuid "${frisbeeCatUuid}"
[/#if]
Copy
Category workspace
Gets the name of the category workspace. When using a search method
where you have to provide the workspace name, use this function instead
of a hard-coded literal value.
[#assign frisbeeNode = catfn.getCategoryNodeByName("frisbee")!]
[#if frisbeeNode??]The node was created by ${cmsfn.metaData(cmsfn.asContentMap(frisbeeNode), "mgnl:createdBy")!"Mr. X"}[/#if]
Copy
Get page based on template type and subtype
Gets a page based on the defined type and subtype properties in the
page definition.
You can provide any values for type and subtype. Use this
function, for example, to find a custom category page
that you have defined yourself.
You can limit the search to a specific site or branch by passing the
root page node in the siteRoot argument.