What we have learned so far controls the output of the linked articles on the article page.

But what if you are also outputting this Articles Field somewhere else in your site through Articles Anywhere, and you would like to display it with a different layout there?

In this tutorial, you will learn how to create and use an alternate Value Layout for Articles Field when displaying it with Articles Anywhere in Joomla 3.

Note: Value Layouts are only available in the Joomla 3 version of Articles Anywhere, as the Joomla 4 version handles things differently.

Introduction

As you may know, with Articles Anywhere (another Regular Labs extension), you can insert any Joomla articles data anywhere on your site.

And with the Pro version of Articles Anywhere, you can display any Joomla! Custom Field of an article using the name of that specific field. Let's say you want to show the value of the custom field "Speaker" - which has a field name speaker - of article "Conference". You can simply do:

{article Conference}
[speaker]
{/article}

When displaying a field of type Articles Field, Articles Anywhere will correctly use the Output and Layout you have defined for the field.

But what if you would like to output an Articles Field with a different/alternate layout when displaying it through Articles Anywhere?

Well, Articles Anywhere does allow you to customize the output of a custom field. So yes, this can also be done for fields of type Articles Field!

Let's take a look at how this is done, along with code examples to create the alternate layout for Articles Fields.

Note: The ability to create an alternate Value Layout for "Articles Field" is only possible when using the "Articles" field type. It won't work when the field uses the "Articles - Linked" type, as in that case the field value is just a toggle between true or false.

Setting the Layout File in Articles Anywhere

In the custom field data tag, you can pass your custom layout file with a value_layout="..." attribute.

If you place the file inside the templates/my_template/html/layouts/com_fields/field/ folder in your template, you can simply insert the name of the file.

{article Conference}[speaker value_layout="speaker-alt-layout"]{/article}

Alternatively, you can also insert the full path to your custom layout file:

{article Conference}[speaker value_layout="templates/my_template/html/layouts/com_fields/field/speaker-alt-layout.php"]{/article}

Simple Layout

Now, what should the file contain?

The following file example will wrap the output of each linked article in a label style (span with a label class):

<?php
defined('_JEXEC') or die;

if (empty($displayData['values']))
{
return;
}
?>
<?php foreach( $displayData['values'] as $id => $output) : ?>
<span class="label" id="item_<?php echo $id; ?>">
<?php echo $output; ?>
</span>
<?php endforeach; ?>

But... that is rather limiting. As you might want to put together a completely different layout compared to what you have defined for the default output.

Fully Custom Layout

For example, say you have "Conference" articles, and for each conference, you can assign "Speakers" articles via Articles Field. In the detailed view of the conference, you want to show a full-size image and the bio of the Speaker (so that's how you have set up the Custom HTML Layout of the field).

However, you would like to only display a resized picture and the name of the speaker on a Timetable page that you created using Articles Anywhere. So you need a completely separate and different layout.

Well, you can do this by using Articles Anywhere again inside this Value Layout file. Yes, pretty crazy inception stuff, but it works! This allows you to take advantage of the full range of Data Tags offered by Articles Anywhere to customize the layout.

The below Value Layout file passes the list of linked articles IDs to Articles Anywhere. Then, Articles Anywhere outputs a resized image and the title for each linked article:

<?php
defined('_JEXEC') or die;

if (empty($displayData['values']))
{
return;
}

$values = $displayData['values'];
$ids = array_keys($values);
?>
{articles articles="<?php echo implode(',', $ids); ?>"}
<div class="item">
<div class="pull-left item-image">
[link][image-intro height="20"][/link]
</div>
[link][title][/link]
</div>
{/articles}

So this is how you create and assign an alternate Value Layout for Articles Field when displaying it with Articles Anywhere. Pretty powerful stuff, isn't it?

For a complete overview of all the features included in Articles Field, head over to the full Documentation, and check out the Video Tutorials.