2

I have the following XML in my module:

<fieldset name="activities" label="Activity Details">
    <field name="image" type="media" directory="images/location" />
    <field name="title" type="text" default="" label="Activity Name" description="Enter Activity Name" filter="raw" />
    <field name="intro" type="textarea" default="" label="Enter intro details" description="" filter="raw"/>
    <field name="links" type="subform" formsource="modules/mod_activities/links.xml" multiple="true" label="Links" description="" />
</fieldset>

then the links.xml subform looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<form>
    <fieldset name="links" label="Links">
        <field name="menulink" type="menuitem" default="45" label="Select a menu item to show" description="Select a menu item" />
    </fieldset>
</form>

I have called them in my module PHP file:

$activities = $params->get('activities');
$links = $params->get('links');

I then call them in a foreach loop in the default.php as follows:

<div id="activities" class="jl-child-width-expand@s" jl-grid>
<?php foreach ($activities as $activity) : ?>
    <div class="jl-card">
        <div class="jl-card-media-top">
            <img src="<?php echo $activity->image; ?>" alt="<?php echo $activity->title; ?>" />
        </div>
        <div class="jl-card-body jl-padding-remove">
            <h3 class="jl-card-title jl-text-primary jl-margin-small-bottom"><?php echo $activity->title; ?></h3>
            <?php echo $activity->intro; ?>

        </div>
        <div class="jl-card-footer">
            <?php var_dump($links); ?>
            <?php var_dump($links); ?>
            <?php foreach ($links as $link) : ?>

                <?php echo $link->menulink; ?>
                <div id="links">
                    <?php var_dump($links); ?>
                </div>

                <a href="#" class="uk-button uk-button-text"><?php echo $link->menulink; ?></a>

            <?php endforeach; ?>

        </div>
    </div>
<?php endforeach; ?>
</div>

'image', 'title' and 'intro' are showing in the frontend, but none of the links are showing. From my var_dump() I'm just getting NULL

2

Access the link fields the same way you're accessing other fields, through the main activities field.

<?php foreach ((array) $activities as $activity) : ?>
    <?php foreach ((array) $activity->links as $link) : ?>
        <?php echo $link->menulink; ?>
    <?php endforeach; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.