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.
tagfn
provides methods to find both content that is tagged and tags applied to content items.These templating functions are provided by the Content Tags module. The java class implementing the methods is TagTemplatingFunctions.
Getting content by tag and adding tags to the tags trait
The method searches content by workspace, root path and a list (array) of tags. Returned content nodes must have at least one of the tags of the given tag array.
Method signature
Set<ContentMap>
getContentByTags(String workspace, String rootPath, String... tagsArray)
Arguments
workspace | required The workspace to search in. |
rootPath | required The root path of the node to search in. |
tagsArray | required Any array of tags. |
Returns
A Set of ContentMap
objects.
Usage
[#assign geniusContacts=tagfn.getContentByTags("contacts", "/", ["genius", "artist"])! /] [#if geniusContacts?has_content] [#list geniusContacts as contact] ${contact.firstName!""} ${contact.lastName!""}[#sep], [/#sep] [/#list] [/#if]
Getting tags by content
Returns the tags of a given content node.
Method signature
Set<String> getTags(ContentMap content)
Arguments
content | required The content map whose tags you want to find. |
Returns
A Set of Strings.
Usage
[#assign contentItem = cmsfn.contentByPath("/ppicasso", "contacts")! /] [#assign tags = tagfn.getTags(contentItem)! /] [#if tags?has_content] ${contentItem.firstName!""} ${contentItem.lastName!""} has the following tags: [#list tags as tag ] ${tag}[#sep], [/#sep] [/#list] [/#if]