如何使用getResources显示文章中的模板变量



我想使用"getResources"在主页上显示"articles"额外部分中的文章。

这是我主页的代码:

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

这是我的sample.ArticlesLatestPostTpl:

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

我的模板变量是[[*myimage]]

但是我看不到文章的模板变量。相反,我看到了主页的模板变量。

有人能帮我吗?

我找到了答案。

我需要写[[+myimage]]而不是[[*myimage]]

正在工作!:)

它的工作原理如下:

  • [[*image]]将显示当前字段"image"内的数据文件
  • [[+image]]将显示所有可以从当前文档中查询的资源
  • [[+tv.image]]可能如果您使用使用"tv."作为模板的"getResources",也可以默认为变量前缀

如果你有疑问,最好的信息是这两页:

常规标记语法:https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/tag-syntax

以及不时使用的默认标签:https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/commonly-used-template-tags

最新更新