如何将变量传递给modx中的子块

时间:2014-03-28 13:01:41

标签: php parameter-passing modx modx-revolution chunks

我在ModX中有一段代码如下:

$array = array(
    'id' => 1,
    'title' => 'Title of Story',
    'content' => 'Content of story...'
);

echo $modx->getChunk('chunk_story_page', $array);

我的故事页面HTML看起来像这样:

<div class="story">
    <h1>[[+title]]</h1>
    <div class="content">
        [[+content]]
    </div>
</div>

现在我希望能够从该块中调用另一个块并通过它传递我的数据。我在上面的HTML下面放了以下内容。

[[$chunk_story_page_extra &title=`[[+title]]`&content=`[[+content]]`]]

不言而喻,但上面的一行并没有产生任何输出。

关于我在这条线上可能做错了什么的任何线索?我确定它与语法有关。

1 个答案:

答案 0 :(得分:3)

您在块名称后面缺少问号:

[[$chunk_story_page_extra? &title=`[[+title]]` &content=`[[+content]]`]]

您也可以这样做,也可能稍微提高效率:

$array = array(
    'id' => 1,
    'title' => 'Title of Story',
    'content' => 'Content of story...'
);
$array['chunk_story_page_extra'] = $modx->getChunk('chunk_story_page_extra', $array);

echo $modx->getChunk('chunk_story_page', $array);

在你的大块中:

[[+chunk_story_page_extra]]

<div class="story">
    <h1>[[+title]]</h1>
    <div class="content">
        [[+content]]
    </div>
</div>