Creating nested MIGX

And when you use this output as value directly?

[[getImageList?
    &value=`[{“MIGX_id”:“1”,“title”:“test”,“icon”:“assets/icons/slipper.png”}]`
    &tpl=`iconlist`
    ]]

or remove the &tpl part? then you should just see the json.


[[getImageList?
    &value=`[[+icons]]`
    ]]

another test could be to un cache the call

[[!getImageList?
    &value=`[[+icons]]`
    &tpl=`iconlist`
    ]]

or any combination to debug this.

Maybe this is a caching problem

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in 

This is your error, that suggest that value is empty, maybe because of caching, try uncached placeholders also [[!+icons]]

or could it be that you have main entries that have no icons at all? maybe that is a problem…

All 3 break the site and just return the errors: just incase this is the full chunk code:

<div class="container">
            <div class="package">
                <div class="row">
                    <div class="col-md-5 col-sm-12"><img src="[[+image]]" alt="" /></div>
                    <div class="col-md-7 col-sm-12 break2">
                        <span>[[+title]]</span>
                        <h2>[[+type]]</h2>
                        <ul>

[[!getImageList?
    &value=`[[+icons]]`
    &tpl=`iconlist`
    ]]
                        </ul> 
                        [[+description]]
                        <div class="tag1">
                            <span>[[+tag1day]]</span>
                            <span class="price">[[+tag1price]]</span>
                        </div>
                        <div class="tag2">
                            <span>[[+tag2day]]</span>
                            <span class="price">[[+tag2price]]</span>
                        </div>
                        <ul class="mcb">
                    <li><a href="">Check Availability</a></li>
                </ul>
                    </div>
                </div>
            </div>
            </div>

Errors returned are:

Spot on, I’ve added icons to each of them and it’s worked, why would 1 not having one break it though ?

You could try this:

[[[[+icons:neq=``:then=`
!getImageList?
    &value=`[[+icons]]`
    &tpl=`iconlist`
    `
]]]]

looks a bit weird with all the [ but that is because you first want to see if icons is not empty then it will remove that and you keep [[ in frond of the result and ]] at the end:

https://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/

Thanks dimmy, I’ll give that a go, thanks allot for all the help on this.

2 Likes

This part should normally make sure that you do not get the error.


if (empty($outputvalue)) {
    $modx->setPlaceholder($totalVar, 0);
    return '';
}

but I think that maybe it saved a string like this: [ ] then this check is not true and if this is the case my example does not work ider unless you say [[[[+icons:neq=`[]`... etc

you can try this changes
fix error in getImageList, when value is not valid json · Bruno17/MIGX@352a909 (github.com)

1 Like

Thanks Dimmy, but neither of these work, both return

[[[[+icons:neq=``:then=`
!getImageList?
    &value=`[[+icons]]`
    &tpl=`iconlist`
    `
]]]]
[[[[+icons:neq=`[]`:then=`
!getImageList?
    &value=`[[+icons]]`
    &tpl=`iconlist`
    `
]]]]

Thanks Bruno, tried that fix but once done it just returns the array.

Thanks allot both, it’s working for me now as each section has content anyway so there will be no empty sections.