Fenom - @INLINE, nesting - return wrong ID

Summary

I’m exploring Fenom and in general template engine in MODx trying to simplify chunks/templates structure to be more dynamic.

Step to reproduce

I have this pdoResoruce call:


[[pdoResources?
&parents=`[[+id]]`
&resources=`[[+includeOrExclude]]`
&depth=`0`
&limit=`0`
&sortby=`{"menuindex":"ASC","pagetitle":"ASC"}`
&includeContent=`1`
&showHidden=`1`
&setTotal=`1`
&totalVar=`sectionCount`
&tplWrapper=`@INLINE <div class="d-flex">[[+output]]</div>`

&tpl=`@INLINE <div class="col-6">
        {if $isfolder}
            {$_modx->runSnippet('pdoResources', [
                'parents' => "{$id}",
                'depth' => 0,
                'sortby' => ['menuindex' => 'ASC'],
                'tpl' => '@INLINE
                {if $isfolder}
                    [[!$textDescriptionItems?&testID=`{$id}`]]
                {else}
                    <div>{$id} single element</div>
                {/if}'
                ])}
        {else}
            <div>{$id}</div>
        {/if}
    </div>`
]]

and then thats the content of textDescriptionItems chunk:

<h1 style="font-size: 120px">[[+testID]]</h1>

[[pdoResources?
    &parents=`[[+testID]]`
    &depth=`1`
    &limit=`0`
    &sortby=`{"menuindex":"ASC","pagetitle":"ASC"}`
    &includeContent=`1`
    &showHidden=`1`
    &setTotal=`1`
    &totalVar=`sectionCount`
    &tplWrapper=`@INLINE <div class="d-flex">[[+output]]</div>`
    &tpl=`testChunk`
]]

and thats content of testChunk:

[[+id]]

Observed behavior

In this part:

<h1 style="font-size: 120px">[[+testID]]</h1>

im reciving correct ID, however once passed to the pdoResrouces:

&parents=`[[+testID]]`

This seems to be invalid because pdoResoruce returns all the IDS - seems like its 0 or invalid so modx thinks no parent i will start from top.

Does anybody know if this sytnax is correct, or maybe something like this is not allowed?

I think the snippet is called with the literal value {id} as the “parents” property (which doesn’t seem to have been replaced with the actual id at the time the snippet runs).


You are using an @INLINE template inside another @INLINE template. I believe this confuses the parser. Maybe try to avoid nested @INLINE templates:

[[pdoResources?
...
&tpl=`@INLINE <div class="col-6">
        {if $isfolder}
            {$_modx->runSnippet('pdoResources', [
                'parents' => "{$id}",
                'depth' => 0,
                'sortby' => ['menuindex' => 'ASC'],
                'tpl' => 'tplFolder'
                ])}
        {else}
            <div>{$id}</div>
        {/if}
    </div>`
]]

Chunk “tplFolder”

{if $isfolder}
    [[$textDescriptionItems?&testID=`{$id}`]]
{else}
    <div>{$id} single element</div>
{/if}

or

{if $isfolder}
    {'textDescriptionItems' | chunk : ['testID' => $id]}
{else}
    <div>{$id} single element</div>
{/if}

Also personally I would try to avoid mixing MODX tags and Fenom too much, as it gets very hard to determine what gets parsed when and in which order.

2 Likes