I have an ajax call. I want to get a chunk in this ajax call. In this chunk it contains a snippet.
My chunk looks like:
<div > this is the content [[!mySnippet]] </div>
It seems that it does not execute the snippet. It returns this is the content [[!mySnippet]]
and not executed snippet.
I have tried getChunk(), parseChunk()
seems not working.
I have many chunks so i do not want to create resources for each chunks. Is there any way to do it ?
Thanks, Awlad
Are you calling a custom endpoint in your ajax or is it a modx page? If its a custom endpoint like a php page, you need to include modx index.php and run it in API_MODE (See this page for description: http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/loading-modx-externally).
After youve included modx you'll be able to do $modx->runSnippet('mySnippet'), but you'll have to modify the chunk since doing $modx->getChunk('yourChunk') won't execute any snippets inside it. If you want to use the same chunk, you could parse it yourself afterwards like this;
$snippetData = $modx->runSnippet('mySnippet');
$chunkHtml = $modx->getChunk('yourChunk');
$finalOutput = str_replace('[[!mySnippet]]', $snippetData, $chunkHtml);