I have built a module using Joomla's subform XML. The XML in the subform is

    <fieldset name="topics" label="Topic">
       <field name="title" type="text" default="" label="Title" description="" filter="raw" />
       <field name="image" type="media" directory="" />
       <field name="description" type="editor" label="Content" description="" filter="safehtml" />

I need to show a button for each of the loops which acts as an anchor to the output. So it looks something similar to this

enter image description here

1 Answer 1


Firstly, fetch the topics in your mod_xxxx.php:

$topics = $params->get('topics');
$topics = gettype($topics) === 'string' ? json_decode($topics) : $topics;

Then, in your default.php, you can perform the iteration:

<?php // Create the triggers ?>
<?php foreach ($topics as $key => $topic) : ?>
    <a href="#topic-<?php echo $key; ?>" class="btn btn-primary">
        <?php echo $topic->title; ?>
<?php endforeach; ?>

<?php // Create the anchors ?>
<?php foreach ($topics as $key => $topic) : ?>
    <article id="topic-<?php echo $key; ?>">
        <h3><?php echo $topic->title; ?></h3>
        <img src="<?php echo $topic->image; ?>" alt="<?php echo $topic->title; ?>">
        <?php echo $topic->description; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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