phpjoomlajoomla-extensionsjoomla-component

Output Joomla subform


OK, I have tried the info from another suggestion on stackexchange, but I seem to be missing something.

I have a subform in an admin view for a component I am working on (they were previously repeatable fields). Admin works perfect, but I am having trouble getting the json to display correctly on the frontend site view.

The fields that are being pulled into the view are in a layout, so it's a little different than in the site view ($displayData instead of $items).

In the db I have a field called appliances, and 4 items in the field are {"appliances1":{"appliance_type":"Dishwasher"},"appliances2":{"appliance_type":"Range"},"appliances3":{"appliance_type":"Microwave"},"appliances4":{"appliance_type":"Washer/Dryer"}}

OK. That looks good and properly formatted.

On the frontend, in the layout for a view, I have:

<?php
print_r($displayData->appliances); 

foreach ($displayData->appliances as $item) : ?> <div>
<p>
<?php echo $displayData->appliance_type; ?>
</p>
</div>
<?php endforeach; ?>

the print_r shows:

Appliances Array ( [appliances1] => Array ( [appliance_type] => Dishwasher ) [appliances2] => Array ( [appliance_type] => Range ) [appliances3] => Array ( [appliance_type] => Microwave ) [appliances4] => Array ( [appliance_type] => Washer/Dryer ) )

OK. again, that looks good. I'll remove that as soon at its working properly.

The problem is that

<p>
<?php echo $displayData->appliance_type; ?>
</p> 

doesn't display anything.

I can see in the code, that it's doing the foreach correctly, but it's not grabbing anything from the array:

Array ( [appliances1] => Array ( [appliance_type] => Dishwasher ) [appliances2] => Array ( [appliance_type] => Range ) [appliances3] => Array ( [appliance_type] => Microwave ) [appliances4] => Array ( [appliance_type] => Washer/Dryer ) ) <div> <p> </p> </div> <div> <p> </p> </div> <div> <p> </p> </div> <div> <p> </p> </div>

Any thoughts on what I may be missing?


Solution

  • OK. I knew I wasn't going to be able to sleep until I tackled this. It may not be the cleanest, yet, but this works for outputting data from a Joomla Subform:

    <?php $records = $displayData->appliances; ?>
    <?php foreach ($records as $key => $value) {
        echo $value["appliance_type"] ."<br>";
        }
    ?>
    

    Result:

    Appliances
    
    Dishwasher
    Range
    Microwave
    Washer/Dryer