modx revo ajax调用不执行chunk内的片段

时间:2014-09-08 05:26:28

标签: modx modx-revolution

我有一个ajax电话。我希望在这个ajax调用中获得一大块。在这个块中它包含一个片段。

我的块看起来像:

<div > this is the content [[!mySnippet]] </div>

似乎它没有执行代码段。 It returns this is the content [[!mySnippet]]并且未执行代码段。

我试过getChunk(), parseChunk()似乎无法正常工作。 我有很多块,所以我不想为每个块创建资源。有没有办法做到这一点?

谢谢, Awlad

2 个答案:

答案 0 :(得分:2)

str_replace('[[!mySnippet]]', $snippetData, $chunkHtml); - 将是一个临时解决方案,但如果您将来需要完整解析所有modx标签和输入/输出过滤器,我建议您使用此代码:

// your chunk
$msg = "<div > this is the content [[!mySnippet:empty=`no data`]] </div>";

// Parse all MODX tags in results
$maxIterations = (integer) $modx->getOption('parser_max_iterations', null, 10);
$modx->getParser()->processElementTags('', $msg, false, false, '[[', ']]', array(), $maxIterations);
$modx->getParser()->processElementTags('', $msg, true, true, '[[', ']]', array(), $maxIterations);

// output result as example
print $msg;

答案 1 :(得分:1)

您是在ajax中调用自定义端点还是modx页面?如果它是一个自定义端点,如php页面,则需要包含modx index.php并在API_MODE中运行它(请参阅此页面了解说明:http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/loading-modx-externally)。

在你加入modx之后,你将能够执行$ modx-&gt; runSnippet(&#39; mySnippet&#39;),但是你需要修改这个块,因为你做了$ modx-&gt ; getChunk(&#39; yourChunk&#39;)不会执行其中的任何片段。如果你想使用相同的块,你可以像以后一样自己解析它;

$snippetData = $modx->runSnippet('mySnippet');
$chunkHtml = $modx->getChunk('yourChunk');
$finalOutput = str_replace('[[!mySnippet]]', $snippetData, $chunkHtml);