We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29635
    • 361 Posts
    Is there any additional information on using the save parameter?
    I’m trying to use PHx to say, "If Ditto has output, then do this, else do something else", but the [+dittoid_ditto_object+] and [+dittoid_ditto_resource+] placeholders don’t seem to return anything, regardless of which save mode I try.

    I’m assuming that it’s because it’s a placeholder for the object itself and not the output of the Ditto call, but is there a way to get Ditto to actually output to a placeholder? I could have sworn there was, but I’m not seeing anything in the code or docs other than the save parameter.

    Thanks for any ideas.
      Need MODx Ecommerce? Try FoxyCart!
      • 11975
      • 2,542 Posts
      Hi Brett,

      you can use the [+total+] placeholder instead.

      [+total:isnot=``:then=``+]

      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 29635
        • 361 Posts
        Thanks for the response, Heliotrope. I wouldn’t have thought of that. In case anybody else needs this, keep in mind you’ll need to add &paginate=`1` and &paginateAlwaysShowLinks=`1` to your ditto call to get the [+total+] to show up.

        So that takes care of the bigger issue, but as far as the actual Ditto output going to a placeholder, is that possible? Without some way to output to a placeholder I’d need to duplicate the Ditto call, which isn’t the end of the world, but I’d rather not if it’s avoidable.
        [[Ditto? &parents=`39` &tpl=`event_link_mini` &display=`100` &id=`seminars` &sortBy=`date_start` &sortDir=`ASC` ]]
        [+phx:if=`[+seminars_total+]`:ne=``:then=`
        <div class="container">
        	<h2 class="h1">Seminars</h2>
        	[+seminars_ditto_object+] <!-- Ditto call would have to be duplicated here -->
        </div>
        `+]
        


        EDIT: Yeah, outputting to a placeholder is definitely gonna be useful, or the first ditto call (that generates the +total+ placeholder, needs to have its output hidden with CSS or commented out or something...

        EDIT 2: I know this could be accomplished with a format config file, but I’d rather avoid that for a few reasons.
          Need MODx Ecommerce? Try FoxyCart!
          • 14050
          • 788 Posts
          I do not believe you can make use of those placeholders unless you set &save to something besides its default value of 0.  For instance:

          [[Ditto? &parents=`39` &tpl=`event_link_mini` &display=`100` &id=`seminars` &sortBy=`date_start` &sortDir=`ASC` &save=`1`]]
          


          You can find more information here:

          http://ditto.modxcms.com/files/snippet-ditto-php.html#save
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 29635
            • 361 Posts
            Right, but regardless the value (1, 2, 3) the placeholders don’t generate anything. At least, not for me.

            The code I pasted above was the workaround, since I can’t get &save to actually do anything (except not output anything).
            The Ditto code actually replaces [+ _ditto_object+] with $ditto itself, the entire Ditto object, not the output, so I think that’s why it’s not replacing the placeholder with the output (unless I’m missing something about the makeup of the $ditto object itself).

            At this point I’ve worked around the issue with the [+total+] idea and commenting out the first Ditto call’s output, but I’m still kind of curious if it’s possible.
              Need MODx Ecommerce? Try FoxyCart!
              • 14050
              • 788 Posts
              It would have probably helped if I reread your original post after looking at ditto and seeing that you quite clearly were talking about what I mentioned grin. Now let’s see if I can be of a little help. I do not think Ditto places its output in a placeholder. However, have you considered coding your own snippet to do exactly what you are looking to do? Something like this:

              <?php
              
              $dittoParams = array(
              			'parents' => '39', 
              			'tpl' => 'event_link_mini',
              			'display' => '100', 
              			'sortBy' => 'date_start', 
              			'sortDir' => 'ASC', 
              			'id' => 'seminars'
                                  );
              
              $dittoOutput = $modx->runSnippet('Ditto', $dittoParams);
              
              if ($dittoOutput != '') {
                  return THIS;
              } else {
                  return THIS;
              }
              
              ?>
              
                Jesse R.
                Consider trying something new and extraordinary.
                Illinois Wine

                Have you considered donating to MODx lately?
                Donate now. Every contribution helps.