We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29181
    • 480 Posts
    After initially not being sure as to whether I could call a snippet within a Ditto template I checked the forums and it appeared that lots of people were doing it.

    However calling something like:
    		<td colspan="4" width="423" height="49" >[!Wayfinder!]</td>
    


    doesn’t parse the snippet...it just outputs [!Wayfinder!] as you can see at http://www.olson.bz/index.php?id=4009&recipe=79

    I’m not using any editors or anything like that. Am I right in assuming that a ditto template can have snippet calls?

    If so, does anyone know how I can sort this out?

    Thanks for any pointers smiley

    Taff

      Adrian Lawley: www.adrianlawley.com
      • 29181
      • 480 Posts
      I spent quite a few hours testing before posting...but it appears to work now, but only if I call a snippet like [[Wayfinder]]

      If however I try to append a few parameters to it..I still have trouble

      huh
        Adrian Lawley: www.adrianlawley.com
        • 4707
        • 73 Posts
        If you have your Ditto call uncached [!Ditto!], then your inner Wayfinder call has to be called cached [[Wayfinder]].

        Can you post your Wayfinder call with parameters?
          • 29181
          • 480 Posts
          Hi and thanks for answering smiley

          I am actually calling the Ditto snippet through another snippet.

          Basically I’m trying to create a half decent dynamic printable version of a recipe.

          My PrintDocument snippet looks like this at the moment:

          <?php
          $doc_id=trim($_REQUEST['recipe']);
          echo $doc_id." is the id of the document we came from<br />";
          
          $runDitto=$modx->runSnippet(
          'Ditto',
          array(
          documents=> $doc_id,
          tpl=>'DittoTemplate',
          phx=>'1',
          ));
          
          return $runDitto;
          ?>


          which allows me to pass the document id via a link so I know which recipe it is that needs parsing.

          Then in the actual ditto template I need to call another snippet (not actually Wayfinder that was just as an example) with which I need to pass the [+content+] as a parameter. I need to check out exactly how much is in the content variable so that I can play around with it so as to make it fit properly.

          <td colspan="4" width="423" height="49" >[!SplitContent?&str=`[+content+]`!]</td>


          is how it should work then. I presume the square brackets are the problem...or the uncached thing you mentioned, but how can I change that if I’m calling the snippet thru another snippet?

          Thanks again for answering...and hopefully you can show me the error of my ways!

          Cheers,
          Taff
            Adrian Lawley: www.adrianlawley.com
            • 4707
            • 73 Posts
            I’m sorry but the question has just got out of my league grin
              • 18397
              • 3,250 Posts
              Try changing [!SplitContent?&str=`[+content+]`!] to [[ style brackets.
                • 29181
                • 480 Posts
                Thanks for the reply.

                I tried your suggestion but as you can see at http://www.olson.bz/index.php?id=4009&recipe=79 it’s still not parsing the snippet, just outputting the snippet call with [+content+] in the middle. I haven’t used any text editor type things. I didn’t copy and paste. I tried removing it and then placing it again...all to no avail.

                As I mentioned, calling the snippet without any parameters [[SplitContent]] works, but obviously I need to pass the contents of [+content+] grin to the snippet so i can split it into rows if there is more than a particular number of
                in there.

                I’d appreciate any other suggestions, as I’ve just hit a brick wall. :’(

                Cheers,
                Taff
                  Adrian Lawley: www.adrianlawley.com
                  • 4707
                  • 73 Posts
                  Maybe you don’t need to use Ditto.

                  If you use this code in your PrintDocument snippet you’ll get the content of your document.
                  $document = $modx->getDocument($doc_id);
                  $doc_content = $document['content'];
                  


                  Then, you can either merge your SplitContent snippet with PrintDocument or keep them separate and pass php variables between snippets.
                    • 29181
                    • 480 Posts
                    Actually, that is pretty similar to my solution.

                    After hitting that brick wall, I also wondered if indeed I needed all that Ditto functionality, and then went with

                    $doc_id=trim($_REQUEST[’recipe’]);
                    $result=$modx-> getTemplateVarOutput($idname=array("RecipeTitle","NoOfServings","PrepTime", "CookingTime", "RecipeImage", "marinadeTime", "marinadeIngredients", "content", "Step1","Step2","Step3","Step4","Step5","Step6","Step7","Step8","Step9","Step10"), $doc_id);

                    to get all the template variables for the document that I need. I then parsed them a little to get them into a table.

                    I still need to sort out the template to make it printable, but at least now I have everything I need where I need it.

                    Click on the "Prink link" at http://www.olson.bz/index.php?id=79 to see the data put into tables. Still waiting on the layout for print.

                    Thanks again for all your help!
                    Taff
                      Adrian Lawley: www.adrianlawley.com
                      • 7455
                      • 2,204 Posts
                      mm I have a similar problem I made a snippet that returns a placeholder but looks like its not working here is the snippet:
                      <?php
                      $lang1="en" ;
                      if ($lang1 == ( ( $_GET['site_lang'] ) ? $_GET['site_lang']: $_COOKIE['site_lang'] ) )
                      {
                      return "[+inleiding_en+]";
                      }else{
                      return"[+introtext+]";
                      }
                      ?>
                      


                      this wil return nothing, looks like the tags are stripped befrore? or do I need to set hiddenFields option?
                      if i remove the [++] then It returns the text. is there an option to return placeholders using a snippet?
                      when i do not use the snippet and place the tag into the chunk directly it works fine. but I need this to be flexible.

                        follow me on twitter: @dimmy01