In this tutorial you will learn how to create Layout Overrides for Custom Fields, when displaying them with Users Anywhere.
Introduction
With the Pro version of Users Anywhere, you can display any Joomla! Custom Field of an user using the name of that specific field.
Let's say you want to show the value of the custom field "Habitat" - that has a field name habitat-area
- of user "Lions". You can simply do:
{user name="Peter van Westen"}[habitat-area]{/user}
If you assigned a Layout to your custom field in its Render Options, Users Anywhere will account for it and output the field using that layout (without the label).
But in the data tag you are able to customize the output of the custom field by setting an alternate Layout. Let's take a look at how this is done:
Create Alternate Field Layout
First, to know exactly how to create an alternative layout file, and to see some layout examples, follow our tutorial on How to create an Alternate Layout for Custom Fields in Joomla.
Now, if you assigned this layout to the fields in its Render Options, this would also apply to the standard output of the field. Which we don't want, since we only want to use this alternate layout in Users Anywhere, without affecting the standard output.
Using the Layout in Users Anywhere
As mentioned, by default Users Anywhere will use the Layout assigned to that custom field in its Render Options.
However, in the data tag you can override the set layout with another one (to be placed inside templates/my_template/html/layouts/com_fields/field/
), by simply inserting the name of the file in the layout="..."
attribute:
[habitat-area layout="habitat-field"]
Value Layout
Example: List Field
Customizing Value Layouts is especially useful if you need further control on custom field types that have multiple values, such as in fields of type "List", or "Checkboxes".
In Users Anywhere, you can now use the new Foreach Structure feature on List Fields to have full control over the output of the values:
<ul>
{foreach data="habitat-area"}
<li>[row]</li>
{/foreach}
</ul>
Check the dedicated page for details on how to use it, which includes how to output the multiple values in a bullet points list.
Example: Articles Field
Articles Field from Regular Labs is a Joomla! custom field type that gives you the ability to choose and display a list of users, allowing you to directly link users to each other.
The Pro version of Articles Field already allows to fully customize the output of the linked users in the user page, thanks to its Custom HTML Layout feature. But what if you would like to output an Articles Field with a different/alternate layout when displaying it through Users Anywhere? You can, too!
You can override the custom_html
parameter to pass another Custom HTML Layout to the field.
So if you have an Articles Field called [speaker]
, you can simply override the Custom HTML Layout set in the field parameters by doing:
[speaker custom_html="<a href='[url]'>[title]</a>"]
And yes, you can use any of the data available for the Articles Field Layout, along with any Custom HTML you want. The only thing you have to be careful of, is the editor not messing up your syntax. So you may need to use single quotes instead of double quotes, but that's just fine as well.
You can even add/override separators between the users returned by Articles Field, if you desire:
[speaker separator=", " last-separator=" and " custom_html="<a href='[url]'>[title]</a>"]