I’m running a tpl in getimagelist and in it I have a custom snippet that loads a user’s extended fields. Below is my snippet call and code. I am calling the getimagelist uncached and the custom snippet uncached.
The issue I’m getting is that if an extended field is empty or is not defined, it loads the last found field, causing duplicate data. My work around was this
The problem is not that the snippet is called cached or uncached.
The problem is, that the placeholders you created with $modx->toPlaceholders exist, until you overwrite or remove them. If you don’t overwrite them with a new value, they still exist with the value of the previous data-item.
Maybe you can delete all your custom placeholders before setting the new ones:
...
$modx->unsetPlaceholders('ez.'); //delete all placeholders that start with 'ez.'
$modx->toPlaceholders($extended, 'ez');
...
Ok…there is a new and odd issue now. unsetPlaceholders does clear the placeholders, however it it now loading the last item extended fields and setting it as the placeholders for other items. Let me explain in detail
let say getimagelist outputs 5 items
item 1 and item 5 has as extended field name called “description”
item 2, 3, 4 do not have an extended field name called “description” (extended field not created/set)
item 2, 3, 4 uses item 5 extended field name “description” as their placeholder
Because the MODX parser uses multiple iterations, it initially doesn’t remove placeholder tags if there exists no corresponding placeholder. The placeholders are left in place to be (possibly) replaced in a later iteration.
If think for a clean solution, you should probably directly use $modx->getChunk('...'); in your custom snippet (instead of setting placeholders).
Or create your own custom version of the snippet “getImageList” and add your additional values to the $fields array before the template-chunk gets parsed.
Just put your placeholders in the Tpl chunk. You’ll need to add in the placeholder prefix for the fields that use it (if any). You don’t really need the prefix unless the field names might collide with other placeholders on the page.