modx revo ajax call don't execute snippet in chunk



我有一个ajax调用。我想在这个ajax调用中得到一块。在这个区块中,它包含一个片段。

我的区块看起来像:

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

它似乎没有执行该片段。It returns this is the content [[!mySnippet]]和未执行的代码段。

我试过getChunk(), parseChunk()似乎不起作用。我有很多块,所以我不想为每个块创建资源。有什么办法吗?

谢谢,Awlad

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;

您是在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->runSnippet('mySnippet'),但你必须修改区块,因为执行$modx->getChunk('yourChunk')不会执行其中的任何片段。如果你想使用相同的区块,你可以像这样自己解析它;

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

最新更新