I am using a repeatable custom field for articles in Joomla! 3.9.16 with an alternative layout (override) of
com_fields/layouts/field/render.php
and an override ofplugins/fields/repeatable/tmpl/repeatable.php
to show the fields content in columns "After Display". This is working fine.The number of columns should depend on the value of a radio-field of the same field-group without "Automatic Display". I can not get this running.
The problem is that I do not get the value of this radio field into the field-layout. I think this is because I do not get the item-id
of the current article via $this->item
or $displayData['item']
. It is no problem to get the 'number-of-columns' value in other overrides like the fields-layout com_fields/layouts/fields/render.php
or the often used blog_item.php
etc., but I want to do this just in the alternative layout if possible.
The following render.php is a simpler version of my code without stuff like links or images and without all the different versions I tried to get the field-value of 'number-of-columns'
to $numberOfColumns
. Just kept the variable where it should be echoed.
I was looking into almost every question about "custom fields" on stackexchange and other sites. Did try the helpers and different answers to fetch the item-id and field-values but without any luck.
render.php
<?php
defined('_JEXEC') or die;
if (!key_exists('field', $displayData))
{
return;
}
$field = $displayData['field'];
$value = $field->value;
if ($value == '')
{
return;
}
?>
<div class="cols-<?php echo $numberOfColumns; ?>">
<?php
$obj = json_decode($value, true);
foreach ($obj as $value) :
$headline = $value['Headline'];
$text= $value['Text'];
?>
<div class="item">
<h3><?php echo $headline; ?></h3>
<div class="content-wrapper">
<p><?php echo $text; ?></p>
</div>
</div>
<?php endforeach; ?>
</div>
repeatable.php
defined('_JEXEC') or die;
$fieldValue = $field->value;
if ($fieldValue === '')
{
return;
}
// Get the values
$fieldValues = json_decode($fieldValue, true);
if (empty($fieldValues))
{
return;
}
echo $fieldValue;