We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27607
    • 5 Posts
    Hello,

    I have been successfully using Ditto for some basic lists + filters. But now I have a growing catalogue and I need a possibility to introduce filters based on user supplied criteria. Let me give you an example.

    Say, I have a list of documents with two Template Variables assigned and set: Media type (say it can be DVD, Divx), Genre (say: Horror, Comedy, Action).

    Now, I need to display a form stating:

    Choose media type [Drop down box] Choose Genre [Drop down box] [Submit]

    After a user clicks submit, I need to supply these selection criteria to Ditto and use it as a filter for selection.

    So, I know vaguely what I need to do - I need to send a $_POST request, then analyze this request, create a &filter string and supply it to Ditto. But maybe someone has already done something similar?

    Also, how would I then be able to clean up the search criteria?

    Your help will be greatly appreciated!
      • 9549
      • 93 Posts
      I did my own little version of a "Ditto Selection Filtering". I don’t know how well this snippet does performance-wise but it works. I hope you guys could give me some feedback! Maybe there is an smoother way for this... but here you go:

      <?php
      // Get the variables from the form
      $showFritext = $_POST['fritext'];
      $showLan = $_POST['lan'];
      $showKommun = $_POST['kommun'];
      
      // "Some" if statements
      if ( $showLan >0 ) {
      $output1 = "tvlan,$showLan";
      }
      
      if ( $showKommun >1 ) {
      $output2 = "|tvkommun,$showKommun";
      }
      
      if ( $showLan == 0 && $showFritext == "") {
      $output2 = "tvkommun,$showKommun";
      }
      
      if ( $showFritext != "") {
      $output3 = "pagetitle,$showFritext";
      }
      
      if ( $showLan == 0 && $showKommun == 0 && $showFritext == "" ) {
      $filter = "";
      }
      else {
      $filter = "&filter=`$output1|$output2|$output3`";
      }
      
      // Output the Ditto call
      echo "[[Ditto? &startID=`2` &tpl=`ListArt` &summarize=`10` &paginate=`1` &extenders=`summary` &sortBy=`createdon` &sortDir=`DESC` $filter]]";
      ?>
      


        • 7231
        • 4,205 Posts
        Clever idea, thanks for sharing.
        I can’t say if this is more efficient but you could run Ditto directly from the snippet with the runSnippet API function.

        http://wiki.modxcms.com/index.php/API:runSnippet
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 11975
          • 2,542 Posts
          Hi,

          I would advice you to use tvExplorer Instead.

          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l