We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38926
    • 33 Posts
    Running into a problem here that I haven't been able to find any previous case of.

    I'm making a new menu point in the admin menu and that means I'm working with the external index.php file. I'm making a database request, and sending the result array to a chunk with getchunk(). Now my problem is that my chunk contains a snippet call, but that snippet call is outputted as just the snippet call itself, it's not being parsed at all.

    Fx. if we say that this is the index.php:

    $output = getChunk('myChunk', $myArgs)
    
    return $output;
    


    And this is the chunk:

    <div>[[!mySnippet? &id=`1`t]]</div>


    Then instead of the processed output, my output is basically just:

    <div>[[!mySnippet? &id=`1`t]]</div>

    Calling a chunk from inside a resource works like a charm though, with the snippet being rendered out and I have used that lots of times. But now that I've gotta call the chunk from an external php file, it doesnt actually render out the chunk.

    Is there anything I can do to make it render the result of the snippet? Or am I forced to redesign the way I use chunks?
      • 38926
      • 33 Posts
      Okay, I might have found a solution to the problem, although it kinda feels a litle "hax".

      Basically, instead of having a snippet call inside the chunk I call the snippet outside in the php code, and then pass the result into the argument array that I send to the chunk, and have a placeholder waiting for it.

      If I use my previous example, it's now:

      $mySnippet = $modx->runSnippet('mySnippet', array('id' => 1));
      
      $myArgs['mySnippet'] = $mySnippet;
      
      $output = getChunk('myChunk', $myArgs)
       
      return $output;


      And the chunk is:

      <div>[[+mySnippet]]</div>


      It works and there is probably decidely more dirty work-arounds that could have existed, but it would have been nice if the chunk could render out the snippet call. Guess you can't get everything :/
      • You have to complete the parsing steps; Elements and Resources only parse cacheable tags. See modResponse::outputContent() for all the logic involved in parsing non-cacheable tag content in MODX.
          • 38926
          • 33 Posts
          I'm not quite sure if I understand what to do with it opengeek. Will it parse it if I do something like this?

          $output = $modx->modresponse->outputContent(array(getChunk('myChunk', $myArgs)));
          
          • This is the important part for parsing the tags:

                        /* collect any uncached element tags in the content and process them */
                        $this->modx->getParser();
                        $maxIterations= intval($this->modx->getOption('parser_max_iterations', $options, 10));
                        $this->modx->parser->processElementTags('', $this->modx->resource->_output, true, false, '[[', ']]', array(), $maxIterations);
                        $this->modx->parser->processElementTags('', $this->modx->resource->_output, true, true, '[[', ']]', array(), $maxIterations);
            


            However, depending on the Snippet you are executing, there may be additional dependencies from the MODX request cycle, e.g. $modx->resourceIdentifier, $modx->resource, etc.
              • 38926
              • 33 Posts
              I see. I'll have to work on that. Thank you very much.