catfn
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.
Related categories
Gets all pages with categories related to a given category. Related categories are referenced in the Categories app.
Method signature
Collection<Node> getRelatedCategories(String name)
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]
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.
See RelatedToursModel.java for an example.
|
Method signature
Collection<Node> getContentByCategory (Node node, String name)`
Arguments
Argument | Description |
---|---|
|
required Root node under which you want to look for content (for example, the root page of a site). |
|
required Category name. |
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]
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.
Method signature
Collection<Node> getContentByCategoryIdentifier(String sitePath, String identifier)
Arguments
Argument | Description |
---|---|
|
required Page path. |
|
required Category identifier. |
Usage
catfn.getContentByCategoryIdentifier(sitePath, identifier)
[#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]
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.
Category node by name
Gets the node representing the category defined by categoryName
.
Method signature
Node getCategoryNodeByName(final String categoryName)
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.
Arguments
Argument | Description |
---|---|
|
required Value of the |
|
required Value of the |
|
required Root node under which you want to search for the page. |