How can I show template variables from articles with getResources?

559 views Asked by At

I want to use "getResources" to show the articles from the "articles" extra on my homepage.

Here is the code of my homepage:

[[getResources? &parents=`52` &tpl=`sample.ArticlesLatestPostTpl` &showHidden=`1` &includeContent=`1`   &includeTVs=`1` &processTVs=`1`  ]]

and this is my sample.ArticlesLatestPostTpl:

<li>
[[*myimage]]
  <a href="[[~[[+id]]]]">[[+pagetitle]]</a>
  [[+publishedon:notempty=`<br /> - [[+publishedon:strtotime:date=`%b %d, %Y`]]`]]
</li>

My template variable is [[*myimage]]

But I cannot see the template variable of the article. Instead I see the template variable of the homepage.

Can somebody help me?

2

There are 2 answers

0
peace_love On BEST ANSWER

I found the answer.

Instead of [[*myimage]] I need to write [[+myimage]].

And working! :)

0
Guido Gallenkamp On

It works like this:

  • [[*image]] will display the data inside field "image" of the current document.
  • [[+image]] will display the data inside field "image" of all resources you might query from the current document.
  • [[+tv.image]] may work too, if you use "getResources" that uses "tv." as a Template Variable prefix as default.

Best info if you are in doubt are those two pages:

General tag syntax: https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/tag-syntax

and default tags that are used now and then: https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/commonly-used-template-tags