-
- How to Add a User to a Joomla Group Programmatically
- How to Send Emails in Joomla with PHP
- How to Connect to an External Database in Joomla with PHP
- How to Check If the Current User is Super User in Joomla with PHP
- How to Check if the Current Page Is the Homepage in Joomla with PHP
- How to Create a User Account in Joomla with PHP
- How to Create an Article in Joomla with PHP
- PHP Scripts Collection
Custom Fields
Output a Joomla custom field's value, raw value, label or ID with Smart Tags, for articles and users, including subform rows.
This guide explains how to output the value of a Joomla custom field and access other properties like its label, ID, or raw value using Smart Tags.
Article Custom Fields
To display the value of a custom field in an article, use:
{article.field.NAME}
Replace NAME with the name (not the label) of your custom field.
For example, if you have a custom field named favoriteColor:
{article.field.favoriteColor}
For more details, see the Article Smart Tags guide.
User Custom Fields
To display the value of a custom field of the currently logged-in user, use:
{user.field.NAME}
Example:
{user.field.favoriteColor}
For more details, see the User Account Smart Tags guide.
Common Syntax and Field Properties
You can access additional properties of a custom field by appending the appropriate keyword after the field name.
Return Raw Value
A custom field has both a value and a raw value, which are different in most cases. To return the field's raw value, use:
{article.field.favoriteColor.rawvalue}
Return Field Label
To return the field's label, use:
{article.field.favoriteColor.label}
Return Field ID
To return the field's ID, use:
{article.field.favoriteColor.id}
Subform Fields
If you’re using a Subform field, you can access its content in various ways.
Let’s assume you have a Subform field named customers, with two nested fields: name and age.
Output All Subform Rows
{user.field.customers}
This returns all subform rows as a bullet list.
Output a Specific Row
{user.field.customers.rawvalue.0}
This returns all values from the first row (index 0).
Output a Specific Field from a Specific Row
{user.field.customers.rawvalue.0.age}
This returns the value of the age field in the first row.
Prevent Shortcodes Parsing
By default, Smart Tags prepare the output of custom fields, which means that shortcodes and content plugins inside a field’s value are executed. This can lead to issues such as:
- Plugins being unintentionally executed: For example, if the Email Cloak Plugin runs on a custom field value that contains an email address, it will replace it with JavaScript-based cloaking, which may not be desirable. Similarly, any shortcode in the field will be parsed and rendered.
- Special characters displayed incorrectly: Text fields containing umlauts or other accented characters may appear broken because the field layout echoes the value using
htmlentities($value).
If you want to prevent this behavior and return the field value exactly as entered, you have two options:
1. Disable Smart Tags from preparing custom fields with the modifier:
{user.field.xxx --prepareCustomFields=false}
2. Output the raw field value instead of the prepared one:
{user.field.xxx.rawvalue}