We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17412
    • 270 Posts
    Hi smiley
    I have a template variable: [*item-price*] where a value such as: 45 is added to each document. Ditto is used to display these documents and I need to a drop down menu to sort the items by price (asc) + sort by price (desc)

    I have had a look at "dropdown menu with ditto": http://wiki.modxcms.com/index.php/Dropdown_Menu_with_Ditto
    And also the Results Per Page snippet: http://modxcms.com/forums/index.php/topic,13143.0.html

    Though after hacking away I’m still no further towards producing what I need.

    Please help.
      • 16278
      • 928 Posts
      You can put the logic you need into a &config file that retrieves the required sort order from the URL and sets a placeholder with a link for sorting in the other direction. Here it is with a fairly crude character link (could use an icon image; I really don’t think drop-downs should be used for simple 2-way choices on accessibility grounds):

      In your document
      <div>[+priceDir+]</div>
      [[Ditto? &config=`prices` etc.]]

      Config file prices.config.php in your ditto/configs folder
      <?php
      /* config file prices.config.php
      *  assumes price is a number in template variable "price"
      */
      
      if ($_GET['order'] == 'desc') {
        $order = 'price DESC';
        $orderText = 'highest first <a href="[*id*]?order=asc">v</a>';
      } else {
        $order = 'price ASC';
        $orderText = 'lowest first <a href="[*id*]?order=desc">^</a>';
      }
      
      // next line cribbed from the Ditto snippet call to generate the arrays needed
      $orderBy = array('parsed'=>array(),'custom'=>array(),'unparsed'=>$order);
      
      $modx->setPlaceholder('priceDir',$orderText);
      
      $tpl= '@CODE:<div>[+title+][+price+]</div>';
      
      ?>

      laugh KP
      (Based on example at http://www.pogwatch.com/ditto/ditto-config.html)
        • 17412
        • 270 Posts
        Wow thanks KP! - I’m going to try this out when I get back this evening.
        Thanks very much for your help!

        Al
          • 17412
          • 270 Posts
          I’ve added the code as suggested though cannot get it to work.

          First thing:

          <div>[+priceDir+]</div>
          [[Ditto? &config=`prices` etc.]]


          The placeholder "priceDir" doesn’t appear.
          If I add priceDir to my ditto chunk template is appears though of course it appears for each item rather than just once.

          Is it possible to display placeholders independently of snippets?
            • 16278
            • 928 Posts
            Still working for me on my PC + Apache 2 + PHP 5 + Modx 0.9.6.3 setup. It works whether PHx is enabled or not and whether page settings are "cacheable" or not. Placeholder doesn’t show when I make the Ditto call uncached, though. huh
            KP
              • 17412
              • 270 Posts
              I got it working - changed Ditto to cached and switched off caching in page settings.
              Really appreciate your help!