Joomla Custom Fields Code Inside Articles

Joomla Custom Fields Code Inside Articles with code is an awesome way to show your CF in any position inside an override. Works perfectly on Joomla 4.
The recipe below was created inside an override of ../html/com_content/category/blog_item.php to show Custom Fields inside articles in a Category Blog layout.
Here is the recipe snippet (these numbers [X] are the CF ID):

<div class="awk-cf-wrapper">  
    
		<div class="d-flex justify-content-center mb-3">
		<p class="mx-1"><?php echo $this->item->jcfields[X]->value; ?></p>
		<p class="mx-1"><?php echo $this->item->jcfields[Y]->value; ?></p>
		<?php
        if (!empty($this->item->jcfields[Z]->value)) : ?>
            <div class="awk-event-end-time">
				<?php echo JText::_('AWK_EVENT_UNTIL_TIME'); ?>
                <span class="mx-1"><?php echo $this->item->jcfields[Z]->value; ?></span>
            </div>
        <?php endif; ?>
		</div>
	<p><?php echo $this->item->jcfields[G]->label; ?></p>
    <p class="mb-0"><?php echo $this->item->jcfields[G]->value; ?></p>
	</div>

Another simple and clean recipe:

<?php if (isset($this->item->jcfields[X])): ?>
    <?php echo $this->item->jcfields[X]->value; ?>
<?php endif; ?>
<?php if (isset($this->item->jcfields[Y])): ?>
    <?php echo $this->item->jcfields[Y]->value; ?>
<?php endif; ?>

Cool article and code ideas from “Custom Fields – Episode 4: a step-by-step tutorial”

Scroll to Top