<![CDATA[ getchunk - snippets not executed - My Forums]]> https://forums.modx.com/thread/?thread=35259 <![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-550982 ! will not be parsed]]> donshakespeare May 20, 2017, 07:13 AM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-550982 <![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193278 It turns out, that if you use non-cacheable snippet calls, the parser delays their processing
so it just echos the chunk. I racked my brain for a day and a half over this when it was just about changing a ! to a [.

I’m a newbie to the modx framework, but so far so good.

cheers]]>
jlodell Apr 03, 2008, 12:28 AM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193278
<![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193277 should work. Try building everything into a string and then [tt]return[/tt] rather than echo it. However, the system is only recursive to 10 levels deep, so if you have a very complex site you may be reaching this limit.

Quote from: OpenGeek at Feb 18, 2008, 10:16 PM

There is also a new parameter called properties that allows you to pass in an associative array of replacement variables that will be prefixed with the name of the chunk, e.g. [[+chunkName.var1]] would be a valid placeholder which would return ’the value of var’ when calling the function like so:
<?php
$output = $modx->getChunk('chunkName', array('var' => 'the value of var'));
?>

OpenGeek, is this something that I could implement for the next release of 0.9.6? It seems like an excellent feature that people would use.]]>
sirlancelot Feb 21, 2008, 04:30 PM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193277
<![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193276
FWIW, the future core has a fully recursive, source order parsing algorithm, that will avoid this issue, as well as a singular model of parser execution by which any MODx element (chunk, snippet, or otherwise) can be processed by simply instantiating the object and calling the process() function, as you can see from the implementation of the getChunk function for 0.9.7:
<?php
    function getChunk($chunkName, $properties= array ()) {
        $output= '';
        if ($chunk= $this->getObject('modChunk', array ('name' => $chunkName), true)) {
            $output= $chunk->process($properties);
        }
        return $output;
    }
?>

There is also a new parameter called properties that allows you to pass in an associative array of replacement variables that will be prefixed with the name of the chunk, e.g. [[+chunkName.var1]] would be a valid placeholder which would return ’the value of var’ when calling the function like so:
<?php
$output = $modx->getChunk('chunkName', array('var' => 'the value of var'));
?>
]]>
opengeek Feb 18, 2008, 04:16 PM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193276
<![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193275 sottwell Feb 18, 2008, 02:29 PM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193275 <![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193274 in case others have the same problem one day. I found the function I was looking for in the document.parser.class.inc.php file. It is called evalSnippets(). You simply send the code of a chunk to this function and all snippets in the chunk will be executed. The output is returned as a string. Awsome!

(Important, the snippet needs to be formatted as [[...]] rather than [!...!])

$chunkOutput = $modx->getChunk($nameOfChunk);
$chunkOutputEvaluated = $modx->evalSnippets($chunkOutput);
echo $chunkOutputEvaluated;

]]>
sbuckup Feb 18, 2008, 01:55 PM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193274
<![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193273
The runSnippet() method I also saw in the wiki. However, I will probably rather rethink my entire concept. The original plan was the following (not sure anybody finds that interesting but I write it off my mind now wink ): I have a column on my website where I want to put boxes containing content teasers, tag clouds, announcements, etc. Each box is saved as a chunk. Different sites contain different boxes.

My solution: I define a TV and enter for each site a comma denominated list with the names of the chunks (boxes) I want in that column. A snippet reads out the TV and subsequently opens each of these chunks. So far quite elegant, I thought. The limit is the snippets in the chunks. Many of my boxes have dynamic content and thus require snippets to be executed...

The code looked like this:

$sbar_elements = explode(",",$modx->documentObject['GPGSidebar'][1]);
foreach ($sbar_elements as $value) 
{
  $chunkOutput = $modx->getChunk($value);
  if($chunkOutput)
  {
    echo "<p>".$chunkOutput."</p>";
  }
}


I will opt for a work around but maybe it would be interesting for the future to have a more advanced version of the function parseChunk() which treats the chunk as if it was regularly included into the site via {{...}} rather than just echoing it as text.

Again, many thanks!!

]]>
sbuckup Feb 18, 2008, 03:10 AM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193273
<![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193272
So, you could use $modx->runSnippet() to manually get output for each of the snippets used in the chunk and then use $modx->parseChunk() to parse in the snippet output into the chunk.]]>
garryn Feb 17, 2008, 02:54 PM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193272
<![CDATA[Re: getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193271 http://wiki.modxcms.com/index.php/API:parseChunk

edit: doesn’t work as I thought it would sad]]>
ganeshXL Feb 17, 2008, 01:33 PM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193271
<![CDATA[getchunk - snippets not executed]]> https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193270
I have a problem: in a snippet I get the code of a chunk via the getchunk method. When I use echo to show it on the screen, snippets which are in the chunk are not executed. Is there a way to parse the chunk instead of just "echoeing" it, so that snippets are executed?

Many thanks,

Sebastian]]>
sbuckup Feb 17, 2008, 01:23 PM https://forums.modx.com/thread/35259/getchunk---snippets-not-executed#dis-post-193270