<![CDATA[ chunk inside getResources template not processed correctly - MODX Community Forums]]> https://forums.modx.com/thread/?thread=43748 <![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-537388 Quote from: opengeek at Mar 14, 2012, 07:43 PM
There is no need to escape backticks; the tags are processed from the most deeply nested out...

This is admittedly an edge case since most developers probably don't inline much JavaScript, but ES6 uses the backtick for template strings
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings#Expression_interpolation

var a = 5;
var b = 10;
console.log(`Fifteen is ${a + b} and\nnot ${2 * a + b}.`);
// "Fifteen is 15 and not 20."


Without a way to escape the MODX parsing of backticks, I don't think you could use expression interpolation within MODX templates without triggering the MODX parser.]]>
dinocorn Jan 22, 2016, 06:47 PM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-537388
<![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-472247 Quote from: opengeek at Mar 14, 2012, 09:45 AM

You need a unique tag string for each iteration as any tag that is parsed with the same property values is cached and all instances replaced on the Resource from the first execution. Try adding a dummy property to the tag, like so...

[[$image-news? &idx=`[[+idx]]`]]


And this way you can also call it cacheable, since each run is unique.

Thank you! Thank you! Thank you! Thank you! I've been banging my head on this issue tonight for longer than I'd care to admit. (Now I can move on to banging my head against other issues wink)

I am curious about the reasoning behind this behavior. It doesn't cache the placeholder values in the enclosing chunk on each iteration, so why should it cache the placeholders in the nested chunk (or is it caching the included chunk entirely, but still,the enclosing chunk isn't being cached on each iteration)? Why doesn't indicating that the chunk shouldn't be cached work the way that one would expect? What would happen if the nested chunk had another chunk nested inside of it? (gonna try this one out and see if you have to propagate the dummy property down..). I'm wondering if this is a bug?
]]>
cvick Jul 19, 2013, 04:58 AM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-472247
<![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-428337 orbitalalliance Jun 29, 2012, 10:09 AM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-428337 <![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-418496
[[$galItemNameAndDescr:htmlent? &idx=`[[+idx]]`]]


where the chunk galItemNameAndDesc looks like this:

<p class="galItemTitle">[[+name]]</p>
<p class="galItemDesc">[[+description]]</p>


In the getResources template, this is used thusly:

<a class="cboxgal" rel="colorboxLSP{[[+album]]}" href="[[+image]]" title="[[$galItemNameAndDescr:htmlent? &idx=`[[+idx]]`]]" alt="[[+name]]">

<img class="[[+imgCls]]" src="[[+thumbnail]]" alt="[[+name]]" />

</a>

This allows me to pass html into colorbox, and it's impossible to do so without a chunk in the template.

The above workaround by adding a fake variable idx does fix this problem.
]]>
drwagner13 Apr 02, 2012, 07:52 PM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly?page=2#dis-post-418496
<![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-416048 opengeek Mar 14, 2012, 02:43 PM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-416048 <![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-416038
But one last question, is there a way to escape backticks?
For example could I use this "trick" with the IF addon?

[[If? 
    &subject=`[[+tv.galleryLink]]`
    &operator=`notempty`
    &then=`[[!$gallery-link &idx=`[[+idx]]` ]]`
  ]]


]]>
kiguane Mar 14, 2012, 12:58 PM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-416038
<![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-415994 Quote from: kiguane at Mar 14, 2012, 12:08 PM
Hello,
ie: if cached, it returns me the content of the first resource for all the resources and if not cached, it only returns content for the first resource (others are blank)...

Any idea?
You need a unique tag string for each iteration as any tag that is parsed with the same property values is cached and all instances replaced on the Resource from the first execution. Try adding a dummy property to the tag, like so...

[[$image-news? &idx=`[[+idx]]`]]


And this way you can also call it cacheable, since each run is unique.]]>
opengeek Mar 14, 2012, 09:45 AM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-415994
<![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-415966
I've got the same problem...
All the placeholders in chunks called from within the getResources template are not processed correctly.
ie: if cached, it returns me the content of the first resource for all the resources and if not cached, it only returns content for the first resource (others are blank)...

Here is a sample code:

GetResources call:
[[!getResources? &parents=`1091` &tpl=`news` &sortby=`menuindex` &limit=`20` &includeTVs=`1` &processTVs=`1` &showUnpublished=`1` &showHidden=`1` ]]


Template (chunk) 'news'
<li class="news-item news-[[+idx]]">
<span class="id">[[+idx]]</span>
<h2>[[+pagetitle]]
  [[If? 
  	&subject=`[[+tv.blogLink]]`
  	&operator=`notempty`
	&then=`[[!$blog-link]]`
  ]]
  [[If? 
  	&subject=`[[+tv.galleryLink]]`
  	&operator=`notempty`
	&then=`[[!$gallery-link]]`
  ]]
</h2>
[[!$image-news]]
</li>


(sub) Chunk "image-news" (the "links" chunks are as simple as this one).
This is where the problem occurs...

<img class="image-news" width="900" height="345" title="[[+longtitle]]" src="[[+tv.imageNews]]"></img>


Any idea?]]>
kiguane Mar 14, 2012, 07:08 AM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-415966
<![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-392225
I've tried calling everything uncached but it repeats whatever the value is in the first record of the getResources call.]]>
Hat-rack Sep 03, 2011, 04:23 AM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-392225
<![CDATA[Re: chunk inside getResources template not processed correctly]]> https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-251945

Only other thing I can think of is to try calling the placeholder uncached too. [[!+tv.bookStatus]]
Actually, try everything uncached!]]>
okyanet Jun 11, 2011, 03:06 PM https://forums.modx.com/thread/43748/chunk-inside-getresources-template-not-processed-correctly#dis-post-251945