Show custom Joomla fields only if they contain data

For Joomla! 3.x Coding related discussions, please use:

Moderator: ooffick

Forum rules
Please use the mailing list here: rather than this forum.
Post Reply
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Mar 30, 2019 4:53 pm

Show custom Joomla fields only if they contain data

Post by delonen » Sat Mar 30, 2019 5:03 pm

Hi everyone, sorry for my bad english.

I need a helping hand for a problem regarding the display of the new custom fields available in Joomla! (3.9) in the override of the default.php file. (I'm not a php programmer and this Joomla! website it's for a friend).

Thanks so much to anyone who wants to help me out, Regards.


- This is the com_content for the article (the relative default.php file at the override path SiteName / templates / FirstNameTemplate / html / com_content / article / default.php)

- I have already entered the code to have the custom fields recognized in the default.php file, it works because with single custom fields I can visualize them and manage them

- The code I'm trying uses the if control structure. Perhaps for semantics in some cases it might be "cleaner" to use a for loop, however for now I would prefer this solution (if structure)


1) I would like the html code to be printed ONLY if one of the two values (stard-date or end-date, or both, of course) are inserted.

2) If there is no value entered NO html code must be entered (and therefore not even the container "general-container" with <h2>, <p> and <dl>. ANYTHING!

3) If one of the two values (start-date or end-date) is entered, the div must be printed container, <h2>, <p> the <dl> BUT ONLY THE PAIR <dt> <dd> of the corresponding value entered (and not also the other empty).

THE PROBLEM IS IN POINT 3: I can't find a way to get the effect of point 3 :(



This code contains the internal control structures to make all the container div, <h2>, <p> and <dt> <dd> pairs are displayed only if their value is entered.

DOES NOT WORK, in the sense that it does not return error but prints the general container div, <h2> and <p> always (even if no data is entered) and does not show data if entered (whether it is entered one data or both, never show them!) :(

I also tried to delete the lines

$params->get('start-date') &&
$params->get('end-date') &&

but don't works :(


$showStartDate = isset($myCustomFields['start-date']) and !empty($myCustomFields['start-date']);
$showEndDate = isset($myCustomFields['end-date']) and !empty($myCustomFields['end-date']);

$showDates = $showStartDate || $showEndDate;
if($showDates){ ?>

<div id="contenitore-generale">
<p>testo descrittivo..</p>

<?php if ($params->get('start-date') && $showStartDate) : ?>
<dt>START DATE</dt>
<?php echo $myCustomFields['start-date']; ?>
<?php endif; ?>

<?php if ($params->get('end-date') && $showEndDate) : ?>
<dt>END DATE</dt>
<?php echo $myCustomFields['end-date']; ?>
<?php endif; ?>



<?php } ?>

Joomla! Enthusiast
Joomla! Enthusiast
Posts: 228
Joined: Fri Oct 13, 2017 8:00 pm

Re: Show custom Joomla fields only if they contain data

Post by CDXXonline » Mon Apr 08, 2019 10:36 am

Can't you start your code with a null case? Leave the first set of brackets empty.

if ($fieldvalue == null) { } else {




Post Reply

Return to “Joomla! 3.x Coding”