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

La civiltà nascosta degli Etruschi

E' uscito il libro di Lidia Orlandini dedicato alla religione e alle tradizioni mitologiche degli...

Demoni, donne e mitologia degli etruschi

Ancora gli etruschi. Quelli riscoperti nel rinascimento e approfonditi nel periodo d'oro...

Wine labels

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

Amiata al tratto: fossili e granchi

Ecco una nuova illustrazione al tratto, simile alle antiche incisioni. E' una sfumatura verticale...

Wind mill well woodcut

Looks like a play of words. Latest experiment work with lineart woodcut style engrave. That's our...

Fior di Maremma

Logo concept in forma di incisione antica. Due varianti con fiore e pozzo a vento per richiamare i...