We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22770
    • 285 Posts
    I need to call a snippet from within the template chunk of a ditto call. Is this even possible? I’ve tried several different approaches without luck.

    Basically, I need to perform a basic operation on the contents of a template variable before it is used by the ditto call.

    Anyone tried anything like this?

    My ditto tpl would look something like this:

    <li>[+pagetitle+]<br/>[[SomeSnippet]]</li>


    If using a snippet inside the chunk isn’t possible, is there any other way of running some PHP on the placeholder before it is outputted?
      • 4172
      • 5,888 Posts
      Quote from: PatrickSamphire at May 18, 2009, 10:17 AM


      <li>[+pagetitle+]<br/>[[SomeSnippet]]</li>



      Should work this way. What is the code of your snippet?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Perhaps it would be better to have a snippet with its output loaded into the placeholders array ($modx->setPlaceholder()) then make sure that snippet is called before the Ditto snippet is called.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 22770
          • 285 Posts
          Bruno, all I’m trying to do is strip tags from a template variable, so the snippet is roughly:

          <?php
          $templateVariable = $modx->getTemplateVarOutput(array("someTV"));
          $content=$templateVariable['someTV'];
          return $content;
          ?>

          Assuming this makes sense (!), I’m wondering if the page id is not being passed through ditto to the chunk and then the snippet.

          Susan: How would that work? How would I tell the snippet what pages to retrieve the relevant template variable from before I’d made the ditto call?
            • 4172
            • 5,888 Posts
            Did you also try something like that:
            <li>[+pagetitle+]<br/>[[SomeSnippet? &tvvalue=`[+someTV+]`]]</li>


            <?php
            if (isset($tvvalue)){
            work with $tvvalue;
            }
            return $tvvalue;
            ?>


            or

            <li>[+pagetitle+]<br/>[[SomeSnippet? &docid=`[+id+]`]]</li>


            <?php
            $templateVariable = $modx->getTemplateVarOutput(array("someTV"),$docid);
            $content=$templateVariable['someTV'];
            return $content;
            ?>
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 22770
              • 285 Posts
              Good idea. I’ll try those and report back. Thanks again.
                • 22770
                • 285 Posts
                Okay, for some reason the first of these didn’t work, but the second method did just what I wanted.

                Great stuff! grin