0

スニペットでそのようなことをする方法はありますか:<?php if ([[+idx]]==1) echo "0";<?

ありがとうございました。

4

2 に答える 2

4

テンプレート変数の値を取得する必要がある場合は、これを使用できます

$id = $modx->resource->get('id');//ID of current resource
$name = $modx->resource->get('pagetitle');//title of current resource
$val = $modx->resource->getTVValue('name_of_tv');//get tv value of current resource by name
$val = $modx->resource->getTVValue($tv_id);//get tv value of current resource by ID

migx tv の idx を取得するには、次のようなものが必要です -

<?php
$docid = $modx->resource->get('id'); // id of curent resource
$tvname = 'name_of_your_tv'; // change to yours
$tv = $modx->getObject('modTemplateVar', array('name' => $tvname));
$outputvalue = $tv->renderOutput($docid);
$items = $modx->fromJSON($outputvalue);
$idx = 0; // initialize idx
$output = array();
foreach ($items as $key => $item) {
    $idx++; // increase idx
    $output[] = print_r($item,1); // test output
}
$outputSeparator = "\n";
$o = implode($outputSeparator, $output); // implode output
return $o;

migx スニペットから取得https://github.com/Bruno17/MIGX/blob/master/core/components/migx/elements/snippets/snippet.getImagelist.php

于 2013-03-17T12:18:25.030 に答える
0

おそらく問題のリソースからスニペットを呼び出しているので [あなたですか?] idx をスニペットに渡すことができます....

[[!callMySnippet? &idx=[[+idx]] ]]

次に、スニペットで:

$output = '';
$idx = $scriptProperties['idx'];

if ($idx==1) {
$output = "0";
}

return $output;
于 2013-03-17T15:04:39.197 に答える