My plugin cannot call a snippet within my tpl

Hey all,

I am trying to create a file with a ‘OnDocFormSave’ plugin. When I try to run a snippet (getImageList) within my plugin, I realised that any snippets/placeholders within the tpl are not being executed. Only the fields found within the getImageList are executed. Any idea why this is?

<?php
switch ($modx->event->name)
{

    case 'OnDocFormSave':
        
        if ($resource->get('template') == 12) {
        
        $ids = array('1','2','3','5');
        foreach ($ids as $key => $value){
                
                
                $vehicles .= $modx->runSnippet('getImageList', array(
                    "docid" => $value,
                    "tpl" => "resultsTpl",
                    "tvname" => "results_details",
                    "limit" => 0,
                    "outputSeparator" => ",",
                    "where" => '{"published:=":"1"}',
                )).",";
                
                
            };

        }
        
        break;

}

Tpl

[[!++site_name]] - [[+idx]]: Your result is - [[+result]]

What is returned is

[[!++site_name]] - 1: Your result is - B

I think the problem only occurs with uncached snippets/system-settings.

Maybe try only using cached snippets in the template-chunk or process the tags again, before you write the file.
Something like this may work:

$maxIterations= (integer) $modx->getOption('parser_max_iterations', null, 10);
$modx->parser->processElementTags('', $vehicles, true, true, '[[', ']]', [], $maxIterations);
1 Like

You probably know this, but if the plugin is only attached to one event, there’s no need for the switch statement.

1 Like

This solution works. Thanks for the assist.

Lol…this never crossed my mind but this makes alot of sense :sweat_smile: