I really cant understand why frontend templates in joomla always miss the last step. Basic standard templates never show the potential under the hood.

My previous article explained how to assign and call custom fields in your template layout. When the awesome "repeatable custom fields" came out with 3.9 I believed it was going to work the same exact way. I was wrong. When you call your custom field var contianing the sub repeated fields you get an ugly useless unordered list. So I had to find a way to extract them...

That's why I'm taking this new note, to make it work as I expected. If you did not, read the previous article Custom fields in joomla, the right way!

Describing step by step for everyone who will look for it.

Here how I solved:

1: Remember to call and assign to variables your custom fields, in the template (article, featured or category):

// GET CUSTOM FIELDS
$myFields = array();
foreach($this->item->jcfields as $field) {
$myFields[$field->name] = $field->value;
}

2: The file responsible in echoing the unordered list of repeatable subfield is "\plugins\fields\repeatable\tmpl\repeatable.php". Override it.

3: Repeatable.php is getting a json string from database, with a sequence of all your subfields. The variable $fieldvalue is all we need, just echo it. Replace the following code:

$html = '<ul>';
foreach ($fieldValues as $value)
{
    $html .= '<li>' . implode(', ', $value) . '</li>';
}
$html .= '</ul>';
echo $html;

echo $html;

with

echo $fieldValue;

4: In the template file json decode the repeatable field and assign to a variable. The second parameter (true) in json_decode it's the magic of transforming a static string in a perfect php array.

$dataRepeatableField = json_decode($myFields['repeatable_filed_name'], true);

5: Done! It's now possible to call each repeatable field, stored in a multidimensional array, like so:

echo $dataRepeatableField['fieldname']['repeatablefieldname'];

A foreach loop can echo all the fields formatted the way you want!

I'm quite proud of the result. The potential is huge: you can create and layout custom content with a variable quantity of custom fields in each article content, without using any third party extension.

For example an image gallery with captions, custom size and layout option for each item.  Or everything you can invent mixing the standard joomla fields. The basic joomla templates are just ignoring all the potential of custom fields.

Good coding.

 

Related content

Legno, creatività e vita

Pubblico questo progetto da me realizzato ormai un pò di tempo fa, lo stand fieristico per il...

The last coffee

Needed 4 espresso cups for a visual. Managed the standard fat, the thick napolitan, the glass one,...

A desk of toys

A whole desk scenery full of toys. This was made for a website visual brand. The executive work is...

Wine labels

Wine labeling fly high with graphic design and photography. Working with wine (especially in...

Wine labels

Le etichette da vino danno grande soddisfazione in termini di design. Lavorare con il vino,...

VFV Mobile

Che succede quando si avvolge un van dentro una mappa? Il poster LWAP "All the sailing in a...