getResources and CB that contains chunk with TVs


I have observed somethings strange working with a call of getResources and CB, probably the issues is due to getResources, but maybe somebody know somethings more here.

The case:

  • we have a resource footer included in all our resource via the call
    [[!getResources? &parents=`-1` &resources=`[[*footerpage]]` &tpl=`@INLINE [[+content]]` &processTVs=`1` &includeContent=`1` &includeTVs=`1`]]
  • the resource footer use CB for his composition
  • in the CB layout of this resource I include a chunk [[$address]]
  • that chunk use a couple of TVs as [[*cf.entityname]], [[*cf.telephone]], …

The results:

  • if we access directly to the resource footer everything is ok
  • if we access to any page that include the footer we have a lot of fun!
  • case: the TVs are inside the chunk nothing work, the TVs have his “default value”
  • case: the TVs are outside the chunk is working

a little more of funny:

  • in case we use some MODX modifier like [[++switcher:is='On':then='[[++valueToDisplay:default='complexity']]']] on the value of the system settings inside the chunk that is inside the CB layout, the modifier fails.

So… somebody have some suggestions?

Have a nice day

Hey @webmasterunifr,

What’s happening is that while ContentBlocks parses resource fields and TVs during save of the (footer) resource, it does not parse chunks. This is because if you changed your chunk, you would also need to save your resource again, which makes the chunk rather pointless as a central place to edit.

Now back to your little problem with the TVs located inside the chunk: those are parsed when the resource is requested. Not the footer resource, but the resource that has the footer resource included through getResources.

So any [[*tv_name]] inside the chunk is parsed as if it was a TV value on the resource that is including the footer.

To work around that, you can use the renderResources snippet instead of getResources. renderResources is slower than getResources, but it does parse the resource content as if it is that actual (footer) resource, with the right TV values and stuff like that.

1 Like