Knowledge Base

T4 tags: Content

Last Modified:
10 May 2019
User Level:
Power User

Content (type="content")

Available from the Content Layout T4 tag builder.

Settings for all output methods

Output methods differ depending on the element type:

  1. Normal output (inline) output="normal". Outputs the element by adopting the text style of the page.
  2. Selective output output="selective-output". Used to only output the value of an element if the element is filled in.
  3. Output to fulltext output="fulltext". Outputs the element on a separate page, which can have its own layout.
  4. Output to image (output="image"). Outputs an image and path to the image.
  5. Output to image url (output="imageurl"). Outputs the path to an image.
  6. Output to file (output="file"). Outputs a file and path to the file.
  7. Output to download (output="download"). Not available on the T4 Tag builder. Outputs a file and path to the file, but any links to this Content Item link directly to the file.

Modifiers

NameModifierDescriptionElements
Parse for media library t4 tags medialibrary Converts media library tags to media. Plaintext, HTML, Checkbox, Select box, Multiple select, Radio button, Cascading list, Multiselect list
Parse for navigation t4 tags nav_sections Converts Section Section and content link tags into the link to the published URL. HTML, Section/Content link
Strip out all HTML tags striptags Removes HTML tags. Plaintext, HTML, Checkbox, Select box, Multiple select, Radio button, Cascading list, Multiselect list
Encode special characters to their HTML equivalent htmlentities Converts un-encoded special characters to their HTML equivalent. Please see http://www.econlib.org/library/asciicodes.html for more information. Plaintext, HTML, Checkbox, Select box, Multiple select, Radio button, Cascading list, Multiselect list
Change new lines to HTML line breaks nl2br Converts new lines (\n\n) to an HTML line break <br>. Plaintext only
Convert invalid RSS characters to their XML equivalent rssentities Converts invalid RSS characters to an XML equivalent. Do not use this modifier in combination with Strip out all HTML tags. Plaintext, HTML, Checkbox, Select box, Multiple select, Radio button, Cascading list, Multiselect list
Convert output to be suitable for use in JavaScript js-var Escapes single quotes, double quotes and new lines. Plaintext, HTML, Checkbox, Select box, Multiple select, Radio button, Cascading list, Multiselect list
Encode email addresses to ASCII format encode_emails Converts email addresses to ASCII format. An email address posted on any website can be easily extracted with special email collection programs and used later for sending spam. This allows it to display on a web page as normal but would prevent spam activity. Plaintext, HTML, Checkbox, Select box, Multiple select, Radio button, Cascading list, Multiselect list

Direct edit

Disable direct edit for this element: enable-dedit="false"

This attribute can be used to prevent users from editing content in Direct Edit. This attribute is added to a T4 tag, like below:

You can edit this Content Type element

<h1>Plain text element</h1> <t4 type="content" name="Code only" output="normal" modifiers="medialibrary" enable-dedit="true" />

You cannot edit this Content Type element in direct edit:

<h1>HTML element</h1> <t4 type="content" name="HTML" output="normal" modifiers="medialibrary,nav_sections" enable-dedit="false" />

In most situations this tag enable-dedit will not exist, so its value is therefore considered null. A null value is actually considered true. Only if the value is not null and equals false, does the content element get marked as "not editable". So the below two lines would be considered the same:

<t4 type="content" name="HTML" output="normal" modifiers="medialibrary,nav_sections" /> <t4 type="content" name="HTML" output="normal" modifiers="medialibrary,nav_sections" enable-dedit="true" />

Settings for normal output (inline) (output="normal")

List elements

Further settings can be applied manually for lists under the tags type="content" output="normal"

List entry names, values

List entries have a name and a value and sometimes you need to specify which of these to output. To do this, add the display_field attribute to the T4 tag.

<t4 type="content" name="Element Name" output="normal" display_field="name" />

or

<t4 type="content" name="Element Name" output="normal" display_field="value" />

The use of this code effects the three different List content elements in the following way:

  • Cascading list - The list entry value is displayed by default. If the attribute is missing, the value is published. An exception is when display_field="name" is added.
  • Multiple select - The list entry value is displayed by default. If the attribute is missing, the value is published. An exception is when display_field="name" is added.
  • Multi-select list - The list entry name is displayed by default. This is consistent with how this content element is currently published, and the default does not change for backwards compatibility reasons.
List delimiters

For Multi-select lists and Cascading list elements, the T4 tag for that list element uses a comma (,) to separate the values selected within a Content Item.

For example, if a user selects "Fruit > Apple" and "Fruit > Pear" and "Vegetable > Carrot" list values, the T4 tag outputs "Fruit, Apple, Fruit, Pear, Vegetable, Carrot".

It is possible to change the delimiters used by adding the textual-name-separator and delimiter attributes to the T4 tag.

<t4 type="content" name="Element Name" output="normal" textual-name-separator=">" delimiter="|" />

In the example above, this would output "Fruit>Apple | Fruit>Pear | Vegetable>Carrot".
For a Cascading list element, where only one item can be selected, it only uses the textual-name-separator example: "Fruit>Apple".

Media elements

Further settings can be applied manually for media under the tags type="content" output="normal".

By default, Media elements are formatted using the Media content layout on the Media Content type, but if a specific Media content layout is required, it is possible to add the formatter attribute to the T4 tag to specify the layout to use.

<t4 type="content" name="Featured image for the blog" output="normal" modifiers="" formatter="path/*" />

In the example above, the "Featured image for the blog" media element, is formatted using the "path/*" layout on the Media Content type.

Content owner elements (output="userinfo")

output="userinfo" can be used to output the details of the user.

Tag to output the username, e.g. joebloggs

<t4 type="content" name="Content Owner" output="userinfo" info="username" />

Tag to output the Full Name, e.g. Joe Bloggs

<t4 type="content" name="Content Owner" output="userinfo" info="first_last" />

Tag to output the Lastname, Firstname, e.g. Bloggs, Joe

<t4 type="content" name="Content Owner" output="userinfo" info="last_first" />

Section/Content link elements (output=linktext or output=linkurl)

Using the Tag builder, Section/Content Link elements output the full anchor tag to the selected Section Section or Content Item.

Further settings can be applied manually for section/content links under the tag type="content".

It is possible to generate the URL of the Section Section/content, or the link text for the Section Section/content by using custom T4 tags. The name is set to the name of the Section/Content link element.

The T4 tag to output the link text for the Section Section/content is:

<t4 type="content" name="element-name" output="linktext" />

The T4 tag to output the URL for the Section Section/content is:

<t4 type="content" name="element-name" output="linkurl" />

Example: Create a Content Type that has a media image with a Section Section/content link on it

This example Content type allows end users to select an image from the media library and create a link on the image:

NameTypeCompulsory
Select an Image Media library Yes
Select a Link Section/Content Link Yes

<a href="<t4 type="content" name="Select a Link" output="linkurl" />"><t4 type="content" name="Select an Image" output="normal" modifiers=""/></a>

If a normal T4 tag is used to output Section/Content Link elements, ensure the Parse for Section Navigation tags modifier has been checked on the Content type element.

<t4 type="content" name="element" output="normal" modifiers="nav_sections"/>

Settings for selective output (output="selective-output")

If you have elements in a Content Type which are not required, you can ensure the element is not output if there is no content in the element. 

Selective output is not available with file or image elements. For image elements, consider using the output=image option.

Attributes

type Always set to content type="content"
name Name of the element name="Name"
process-format Process selective output markup, true or false. Use this to process other tags within this tag. process-format="true"
format Selective output markup format="<p>Phone: $value</p>"
modifiers Modifiers modifiers=""
format-modifiers Apply different modifiers (such as, htmlentities) to the Content Type element value and the format attribute. For example, you want characters within the Content Type element value to be changed to their HTML equivalent (change & to &) - but if you have an & in the format tag, and you want it to remain as & in the output. To do this, the "process-format" attribute must be set to true and the format-modifiers attribute is specified. format-modifiers=""

Example of a standard tag

The Content Type has an element "Phone". We only want HTML to be output if the user has added the phone number in the element. If no content has been added to the Phone element then nothing will be published.

<t4 type="content" output="selective-output" modifiers="" name="Phone" format="<p>Phone: $value</p>" />

Example of a tag containing quotes

Quote symbols in the HTML need to be added in their Unicode equivalent.

<t4 type="content" output="selective-output" modifiers="" name="Phone" format="<p class="phone">Phone: $value</p>" />

Example of a tag containing additional t4 tags

The format attribute can contain other T4 tags such as (language variable tag). To do this, the "process-format" attribute must be set to true, and the quote symbols in the nested t4 tag must be replaced with &quot;


<t4 type="content" output="selective-output" process-format="true" modifiers="" name="Name" format="<p><t4 type=&quot;lang-var&quot; default-language=&quot;en&quot; en=&quot;Name&quot; ga=&quot;Irish Name&quot; fr=&quot;French Name&quot; /> : $value</p>" />

Example of a tag containing different modifiers on the element value and format attribute

You can apply different modifiers (such as, htmlentities) to the element value and the format attribute. For example, you want characters within the element value to be changed to their HTML equivalent (change & to &amp;) and if you have an & in the format tag, you want it to remain as & in the output.

To do this, the "process-format" attribute must be set to true and the format-modifiers attribute is specified. You can specify the modifiers as follows:

<t4 type="content" output="selective-output" process-format="true" format-modifiers="" modifiers="htmlentities" name="Full Name" format="<p>First & Lastname : $value</p>" />

Settings for output to fulltext (output="fulltext")

Fulltext formatters can be used to link from one Content layout to another.

Potential usage scenario

As an example: this can be used for news Items to display some of the elements on the main page (index) (Title, Date and Summary), and then link one of the elements (the Title) to the fulltext content layout to display the relevant elements (Title, Date and Main Story). 

Example standard tag

The initial Content layout needs to include a tag to generate the fulltext content. Check the channel settings to find the Type used for the channel, the default being text/html. Use Generate T4 tag, select the output method as Output to Fulltext. You can use any element to generate the fulltext content. By default, the generated URL reflects the selected element. In this case, we have selected the Question element which generates a fulltext URL similar to /mysite/question,123,en.html. 

<t4 type="content" name="Question" output="fulltext" />

A link should be provided to link to the fulltext page:

<a href="<t4 type="content" name="Question" output="fulltext" />">Link text</a>

The element referencing each layout should be unique. If the same element is referencing different fulltext layouts, they will have the same filename and overwrite each other until only the last fulltext file written will be published.

Example tag using an element to set the file name

If you want to be able to control the URL of the fulltext version of the content, you can modify the T4 Tag to use the contents of one of the elements. Specify use-element="true" and the element to be used filename-element="Title". The example below uses the Title element.

The URL for the fulltext version of the content will then contain the text entered in the title element example: "how-to-make-content,en.html".

<t4 type="content" name="Title" output="fulltext" modifiers="" use-element="true" filename-element="Title"/>

 A link should be provided to link to the fulltext page:

<a href="<t4 type="content" name="Title" output="fulltext" modifiers="" use-element="true" filename-element="Title"/>">Link text</a>

Instead of using a T4 Tag, it is possible to select for one of the Content Type Elements to be used using the Use as filename option. If the Use as filename option is used, and a T4 Tag specifies a different element to be used, the Use as filename Element is used for the URL.

Example tag using a specific formatter

If you wish to specify a type formatter to use, the formatter attribute can be set. In the example below, the name of the Content layout is called text/website:


<t4 type="content" name="Question" output="fulltext" modifiers="" formatter="text/website" />

Example of tabbed Content Type using multiple formats

Example of tabbed Content Type using multiple formats
Using the fulltext tag, multiple formats can be created and linked from the one Content Item.
This example splits the content into three tabs for "Contact Info", "Biography" and "Awards". 
Each tab contains some of the elements from the Content Type.

Create a Content Type with the following elements:

NAMETYPECOMPULSORYMAXIMUM SIZE
Name Plain text  Yes  10 words 
Address Plain text  Yes 100 words
Phone number Plain text  Yes 10 words 
Biography HTML Yes 500 words 
Research interests Plain text Yes 100 words
Awards Plain text Yes 100 words 

Create the first Content type layout, using text/html as the name.

<!-- start formatter="text/html" for Content Type -->
<p class="multiFormatter">
<a href="<t4 type="content" name="Biography" output="fulltext" modifiers="" formatter="text/biography"/>">Biography</a>
<a href="<t4 type="content" name="Awards" output="fulltext" modifiers="" formatter="text/other" />">Research and Awards</a>
<h2>Contact details</h2>
<p><strong>Name: </strong><t4 type="content" name="Name" output="normal" modifiers="" /></p>
<p><strong>Address: </strong><t4 type="content" name="Address" output="normal" modifiers="striptags,htmlentities" /></p>
<p><strong>Phone: </strong><t4 type="content" name="Phone number" output="normal" modifiers="striptags,htmlentities" /></p>
<!-- end formatter="text/html" for Content Type -->

Create the second Content type layout, using text/biography as the name.

<!-- start formatter="text/biography" for Content Type -->
<p class="multiFormatter">
<a href="<t4 type="content" name="Name" output="fulltext" modifiers="" formatter="text/html" />">Contact Details</a>
<a href="<t4 type="content" name="Awards" output="fulltext" modifiers="" formatter="text/other" />">Other</a></p>
<h2>Biography details</h2>
<p><strong>Name: </strong><t4 type="content" name="Name" output="normal" modifiers="" /></p>
<p><strong>Biography: </strong><t4 type="content" name="Biography" output="normal" modifiers="medialibrary,nav_sections" /></p>
<!-- end formatter="text/biography" for Content Type -->

Create the third Content type layout, using text/other as the name.

<!-- start formatter="text/other" for Content Type -->
<p class="multiFormatter">
<a href="<t4 type="content" name="Name" output="fulltext" modifiers="" formatter="text/html" />">Contact Details</a>
<a href="<t4 type="content" name="Biography" output="fulltext" modifiers="" formatter="text/biography" />">Biography</a>
<h2>Research & award details</h2>
<p><strong>Name: </strong><t4 type="content" name="Name" output="normal" /></p>
<p><strong>Research Interests: </strong><t4 type="content" name="Research interests" output="normal" modifiers="striptags,htmlentities" /></p>
<p><strong>Awards: </strong><t4 type="content" name="Awards" output="normal" modifiers="striptags,htmlentities" /></p>
<!-- end formatter="text/other" for Content Type -->

When the content is published, 3 files will be published

  1. index.html which will provide links to:
  2. biography-280-en.html
  3. awards-280-en.html

The code in the files will be in the following format

index.html (from the text/html format)

<!-- start formatter="text/html" for Content Type -->
<p class="multiFormatter">
<a href="/multi-fulltext/biography-280-en.html">Biography</a>
<a href="/multi-fulltext/awards-280-en.html">Research and Awards</a>
<h2>Contact details</h2>
<p><strong>Name: </strong>multi fulltext example</p>
<p><strong>Address: </strong>110 Amiens Street</p>
<p><strong>Phone: </strong>018509700</p>
<!-- end formatter="text/html" for Content Type -->

biography-280-en.html (from the text/biography format)

<!-- start formatter="text/biography" for Content Type -->
<p class="multiFormatter">
<a href="/multi-fulltext/name-280-en.html">Contact Details</a>
<a href="/multi-fulltext/awards-280-en.html">Other</a></p>
<h2>Biography details</h2>
<p><strong>Name: </strong>multi fulltext example</p>
<p><strong>Biography: </strong><p>All about the person.</p>
<p> </p></p>
<!-- end formatter="text/biography" for Content Type -->

awards-280-en.html (from the text/other format)

<!-- start formatter="text/other" for Content Type -->
<p class="multiFormatter">
<a href="/multi-fulltext/name-280-en.html">Contact Details</a>
<a href="/multi-fulltext/biography-280-en.html">Biography</a>
<h2>Research & award details</h2>
<p><strong>Name: </strong>multi fulltext example</p>
<p><strong>Research Interests: </strong>Higher education</p>
<p><strong>Awards: </strong>Degrees</p>
<!-- end formatter="text/other" for Content Type --></html>

Notes

If you use the T4 Title tag to create the title of the page, the T4 tag can be modified for fulltext pages to generate a unique Title tag for each fulltext page.

If your Page layout contains a Breadcrumb Navigation object, the object can be configured to include the fulltext content, instead of simply generating a path to the Section Section.

Settings for image output (output="image")

This is used in Content type layouts to format Image elements (not to be confused with Media).

Attributes

type Always set to content. type="content"
name Name of the image element. name="element-name" 
output Always set to image. output="image"  
max-width Forces a maximum width on the image. max-width="100" limits resize to a maximum width of 100 pixels. max-width="100"
max-height Forces a maximum height on the image. max-height="100" limits resize to a maximum height of 100 pixels. max-height="100"
client-resize Specifies if the image resizing is done within the browser or during publish. By default, this is done in the browser. If the attribute has a "false" value, the image is resized on publish, resulting in a new image with the size added to the name. NOTE: this can impact the publish time, as new images have to be created during publish. client-resize="false"
alt The ALT text for the image. alt="This is a blue image"
alt-element The Content type element you want to use for the ALT text. alt-element="Description"
style CSS Style options, examples: border, margin, float and class.
NOTE: The width, height and src attributes are not used with this tag.
 

Example

<t4 type="content" name="element-name" output="image" />

The output would be:

<img src="/mysite/name-of-image-file.jpg" />

Settings for image url output (output="imageurl")

This is used in Content type layouts to output the URL of Image elements (not to be confused with Media).

Attributes

type Always set to content. type="content"
name Name of the image element. name="image-element"
output Always set to imageurl. output="imageurl"
max-width Optional. Forces a maximum width on the image. max-width="55" limits resize to a maximum width of 100 pixels. max-width="55"
max-height Optional. Forces a maximum height on the image. max-height="44" limits resize to a maximum height of 100 pixels. max-height="44"

Example

<t4 type="content" name="the-image" output="imageurl" max-width="55" max-height="44" />

The output would be:


/mysite/name-of-image-file-55x15.jpg

Settings for file output (output="file")

Used to output a path to an Image or File element.

<t4 type="content" name="element" output="file" />

The output would be:

/mysite/name-of-file.jpg

The output of Content Links to this Content Item would be an anchor link to the Content Item on the page (as opposed to the download output that links directly to the file):

<a href="/mysite/#d.en.36301">my content link text</a>

Settings for download output (output="download")

It is not possible to create this T4 Tag through the T4 Tag Builder. To create this tag, build the tag using the file output, and manually change the output in the T4 Tag.

This is used to output the path to an Image or File element. Any links to the Content Item that contains a T4 Tag that uses output="download" will link directly to the file.

This can be useful if the Content Type is used to upload documents. Links would output the direct path to the document rather than link to the page anchor that contains the link.

<t4 type="content" name="element" output="download" />

The output would be:

/mysite/name-of-file.jpg

The output of Content Links to this Content Item would be to the file (as opposed to the file output that links to an anchor on the page):

<a href="/mysite/name-of-file.jpg">my content link text</a>

Fix URL (type="fix-url")

The Fix URL tag checks URLs within a specified Element in a Content Type and prepends http:// to it, as necessary, when published. This is used for Content Types which contain an Element for users to enter a URL. 

The tag does not output the element, so you must also use the normal t4 tag to output the element.

There is a single required attribute, element, the name of the Content Type Element to be checked and updated.

Example:

<t4 type="fix-url" element="External URL" />

Tag output: Metadata (type="meta")

These meta tags are generated for the specific Content Item in the content tab of the tag builder. Please note that under the meta tags tab in the page layout tag builder, further meta tag outputs are available.

Type of metadataTagDate formatNote
HTML anchor meta="html_anchor" HTML anchors are required for content links to work correctly  
Content ID meta="content_id" Output the ID of the Content Item.   
Last modified date meta="last_modified"  The date that the content was last modified. Format the date as required by using the format attribute.  
Last modified by (username) meta="last_modified_by_username" The username of the user who last modified the content. If this user no longer exists, nothing is output.  
Last modified by (full name) meta="last_modified_by_fullname" The full name (Firstname Lastname) of the user who last modified the content. If this user no longer exists, nothing is output.  
Publish date meta="publish_date" The date the content was published. Format the date as required by using the format attribute. This is linked to the Content Options and is only output if the options are chosen.  
Expiry date meta="expiry_date" The date the content is due to expire. Format the date as required by using the format attribute. This is linked to the Content Options and is only output if the options are chosen.  
Content version meta="version" The current version number of the content.  
Element size meta="filesize" The size of a chosen element (typically of a file or media). The output is in KB. The Element Size metadata requires the use of an Element. This will result in an additional drop-down list when building the tag to allow you to select an Element. In the T4 tag, the Element is added as a "name" parameter.  
Number of days since modified meta="recently_modified" The number of days since content was last modified.

 Additional attributes for "threshold" and "text" can be added to this tag which will output the value in the "text" attribute if the content was last modified within the "threshold" days.

 

<t4 type="meta" meta="recently_modified" threshold="2" text="<t4 type="media" id="5" /> NEW: " />

In the example above, where content was modified within the last 2 days (48 hours), this tag would output a media item (media id 5) and text. Notice how quote symbols within the text attribute are changed to " to escape them.