GoodNews: include (image) TV in ContentCollection tpl

I want to make use of the ContentCollection feature within the GoodNews extra, but I can’t figure out, how to display an image TV from the fetched resources.

I tried adding [[+tvname]] and [[+tv.tvname]] to the tpl chunk without luck. Is this possible at all or are TVs not being processed with this snippet?

Looking at the code, it seems that no TVs are processed in the snippet “GoodNewsContentCollection”.

You probably could duplicate the snippet and adjust it to also query your TV.
Use $tv_value = $resource->getTVValue('tvname'); to get the value of the TV and then add it to the $properties array before it is used ($properties['tvname'] = $tv_value):

Thanks a lot! I just added in your recommendations at line 104 which seemed to do the trick.

To future proof this a bit more, I wanted to declare the TVs i want to include so I don’t have to hardcode this.

Therefore I added my own property at the top of the snippet

$includeTVs   = !empty($includeTVs) ? $includeTVs : '';

and then again inserted after $properties = array_merge(...);

if (!empty($includeTVs)) {
  $input = preg_replace('/\s+/', '', $includeTVs);
  $tv_names = explode(',', $input);
  foreach ($tv_names as $tv_name) {
    $tv_value = $resource->getTVValue($tv_name);
    $properties[$tv_name] = $tv_value;

Seems to work so far, or is there anything else I should watch out for?

Just as an alternative to these snippet adjustments:
I think you could use fastField [[#[[+id]].tv.tvname]] in your tpl chunk to achieve the same.

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.