Display Tags on Content

Last Updated: Oct 22, 2019
documentation for the dotCMS Content Management System

The following example shows how to reference content type's Tags field using a Velocity content pull. The tags are displayed both as a string, and individually (by iterating in Velocity over the contents of the Tags field).

#foreach($con in $dotcontent.pull("+contentType:News",10,"modDate desc"))
    ##A tag field contains a List of Strings/Tags
    <strong>Tags</strong> : $con.tags<br/>
    #foreach($tag in $con.tags)
        $tag #if( $foreach.hasNext ), #end
    #end
#end

Note that the #if( $foreach.hasNext ), #end code will add a comma after each tag displayed except the last one, providing a proper comma separated list.

On this page

×

We Dig Feedback

Selected excerpt:

×