I am using the following code to check to see if my repeatable custom field's state is published/unpublished. If the state is set to 0
, the code in between should be hidden, but instead an error is thrown.
Error: Notice: Trying to get property 'state' of non-object
.
The "state" object is outputted as public 'state' => string '1' (length=1)
when I use $programs = $fields['programs']; var_dump($programs);
. I tried changing 0
to '0'
, but this does not work either.
<?php if($fields['programs']->state != 0): ?>
<!-- Code is displayed here. -->
<?php endif; ?>
This code does work to check to see if a text field contains a value, but I am needing to ensure that the repeatable field is published before rendering the HTML and output.
<?php if($fields['article-description']->value != ''): ?>
<!-- Code is displayed here. -->
<?php endif; ?>
Update
The custom fields code is being used in the Article default.php file. I have included how that code is being brought into the file below.
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$context = 'com_content.article';
$article = $this->item;
$fields = FieldsHelper::getFields($context, $article, true);
foreach($fields as $field) {
$fields[$field->name] = $field;
}
When I unpublish the "programs" repeatable custom field, then do a var_dump
of the $programs
variable, Joomla displays this error: Notice: Undefined index: programs
.