Answer the question
In order to leave comments, you need to log in
How to pass a variable (MODX) to a snippet?
Please tell me, I broke my whole head, it does not work. I want to pass a variable to a snippet that is in a loop.
There is a cycle, and a snippet is called in it
{set $tag = json_decode($row.tag, true)}
{foreach $tag as $idx => $row}
<div class="sidebar_info">
{'!pdoResources' | snippet : [
'limit' => 1,
'loadModels' => 'tagger',
'class' => 'TaggerTagResource',
'leftJoin' => '{
"NameTag": {
"class": "TaggerTag",
"on": "TaggerTagResource.tag = NameTag.id"
},
"Posts": {
"class": "modResource",
"on": "TaggerTagResource.resource = Posts.id"
},
"intronews": {
"class": "modTemplateVarResource",
"on": "Posts.id = intronews.contentid and intronews.tmplvarid = 20"
},
"autor": {
"class": "modTemplateVarResource",
"on": "Posts.id = autor.contentid and autor.tmplvarid = 19"
},
"image": {
"class": "modTemplateVarResource",
"on": "Posts.id = image.contentid and image.tmplvarid = 1"
}
}',
'select' => '{
"TaggerTagResource": "*",
"NameTag": "NameTag.tag, NameTag.alias",
"Posts": "Posts.id, Posts.pagetitle",
"intronews": "intronews.value as intronews",
"autor": "autor.value as autor",
"image": "image.value as image"
}',
'where' => '{"NameTag.alias" : $row.section}',
'sortby' => 'createdon',
'sortdir' => 'desc',
'tplWrapper' => '@INLINE {$output}'
'tpl' => 'news_block',
]}
</div>
{/foreach}
'where' => '{"NameTag.alias" : $row.section}',
'where' => '{"NameTag.alias" : "news"}',
'where' => '{"NameTag.alias" : $row.section}',
Answer the question
In order to leave comments, you need to log in
Phew, I fought for two days, I knew it, it's the FENOM syntax, it's difficult. The correct spelling is "'~$row.section~'"
'where' => '{"NameTag.alias" : "'~$row.section~'"}',
And if so:
{set $tag = json_decode($row.tag, true)}
{foreach $tag as $idx => $row}
{set $section = $row.section}
<div class="sidebar_info">
{'!pdoResources' | snippet : [
'limit' => 1,
'loadModels' => 'tagger',
'class' => 'TaggerTagResource',
'leftJoin' => '{
"NameTag": {
"class": "TaggerTag",
"on": "TaggerTagResource.tag = NameTag.id"
},
"Posts": {
"class": "modResource",
"on": "TaggerTagResource.resource = Posts.id"
},
"intronews": {
"class": "modTemplateVarResource",
"on": "Posts.id = intronews.contentid and intronews.tmplvarid = 20"
},
"autor": {
"class": "modTemplateVarResource",
"on": "Posts.id = autor.contentid and autor.tmplvarid = 19"
},
"image": {
"class": "modTemplateVarResource",
"on": "Posts.id = image.contentid and image.tmplvarid = 1"
}
}',
'select' => '{
"TaggerTagResource": "*",
"NameTag": "NameTag.tag, NameTag.alias",
"Posts": "Posts.id, Posts.pagetitle",
"intronews": "intronews.value as intronews",
"autor": "autor.value as autor",
"image": "image.value as image"
}',
'where' => '{"NameTag.alias" : $section}',
'sortby' => 'createdon',
'sortdir' => 'desc',
'tplWrapper' => '@INLINE {$output}'
'tpl' => 'news_block',
]}
</div>
{/foreach}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question