I have an issue with setting up variables - if the custom field is filled then it should be shown, if it's empty - then date (+1 month from today's date) is shown.
However, it doesn't work properly. Custom field values are shown as they should, but I can't get the date if the field value is empty.
<?php
if (isset($fields['exp-date'])) {
echo $field_value = $fields['exp-date']->rawvalue;
$timeset = $fields['exp-date']; // then assign
}
if (!isset($fields['exp-date'])) {
echo (new DateTime('+1 month'))->format('d.m.Y');
$timeset = '';
}
?>
P.S. I get custom fields shown in module using the next code and FieldsHelper (everything works perfectly).
<?php
$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true);
$fields = [];
foreach($item->jcfields as $jcfield)
{
$fields[$jcfield->name] = $jcfield;
}
?>
var_dump($fields['exp-date']);
displayed. Does your code actually need to echo those values, or does it merely need to declare$timeset
?