Tag Wrapper

Tag wrappers provide the properties and methods for interfacing with tags via your twig templates. You will be working with a \Enact\template\wrapper\Tag instance whenever you are interacting with a tag field.

Tag Properties#

  • id - The unique ID of the tag.

  • userId - The unique ID of the user who created the tag.

  • name - The name of the tag.

  • handle - The handle of the tag.

  • usedTimes - The number of times the tag has been used.

  • createdOn - The date the tag was created.

  • sectionId - The unique ID of the section (tag group) the tag is contained in.

  • sectionName - The name of the section (tag group) the tag is contained in.

  • sectionHandle - The handle of the section (tag group) the tag is contained in.

  • entryId - The ID of the entry the tag is associated with (only if tags have entries).

  • entryTitle - The title of the entry the tag is associated with (only if tags have entries).

  • entryUrl - The url of the entry the tag is associated with (only if tags have entries).

Accessing properties

{% set tag = entry.yourFieldHandle.tagFieldHandle[0] %}

<p>Tag name : {{ tag.name }}</p>

<p>Tag handle : {{ tag.handle }}</p>

<p>Used : {{ tag.usedTimes }}</p>

<p>Section : {{ tag.sectionName }}</p>

Tag Methods#

  • getLinkHtml - Returns a a html element with the title and href attributes set that links to the entry the tag is associated with (if the tag doesn't have an entry it will return an empty string). You can pass an array of attributes to the method to set additional attributes on the a element.

  • getEntry - Returns the \Enact\template\wrapper\Entry representing the entry the tag is associated with (if the tag doesn't have an entry it will return null).

  • getTaggedEntries - Get the entries which are tagged by this tag. Call the fetch method immediately after this method to get the tagged entires as an array of \Enact\template\wrapper\Entry, or add more conditions to refine the lookup and then call the fetch method.

Using the methods

{% for tag in entry.yourFieldHandle.tagFieldHandle %}

    {{ tag.getLinkHtml({ 'class' : 'tag-link' }) }}
    // Will output <a href='/path/to/entry' title='entry title'>Tag name</a>

    <p><b>Tagged Entries</b></p>

    <ul>

    {% for e in tag.getTaggedEntries %}

        <li>{{ e }}</li>

    {% endfor %}

    </ul>

{% endfor %}