We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31800
    • 10 Posts
    A stupid problem I have embarrassed

    How should I make Ditto show articles with pagetitle beginning with a particular letter (passed via GET) without making a TV called "first_letter"?
      • 1122
      • 209 Posts
      I wouldn’t say that it is a stupid question smiley The solution is a bit sophisticated rather than simple.

      [[Ditto? &parents=`...` &depth=`...` &tpl=`...` &where=`pagetitle LIKE "b%"`]]
      


      Comment to the code. Ditto has a "where" parameter through which you can pass your own SQL WHERE clause. The above-presented example selects documents whose pagetitles start with "b" (they are selected by SQL expression: pagetitle LIKE "b%").
        • 31800
        • 10 Posts
        Great! Thanks for this brilliant idea.
          • 5699
          • 46 Posts
          computersolutions.cn Reply #4, 18 years, 4 months ago
          How would I go about passing the parameter to Ditto?

          Eg i have an A-Z list, I can generate the URL -> the Ditto page call, but how do i pass the letter?

          My thoughts are - Make a php snippet which generates the parameters then calls ditto directly?

          eg (pseudocode)

          [!AtoZ? &search=`a`!]

          Or called with pagename?&search=a

          where pagename contains [!AtoZ!]

          AtoZ code -

          <?php
          
          if (isset($_GET['search'])) {
                $search = $_GET['search'];
          }  //Get from ?search = if passed
          
          $search = (isset($search))? $search : 'a';  //default to A if not passed
           if (strlen($search)>1) { $search='a';}; //rudimentary param check
          
          $param['parents']='9';
          $param['depth']='0';
          $param['tpl']='AtoZResults';
          $param['where']='pagetitle LIKE "' . $search . '%"';
          
          $output= $modx->runSnippet('Ditto', $param);  //Always prefer to put output in a variable
          
          return $output;
          ?>


          It works, but seems a bit dumb. Am I on the right track, or should I be doing it another way?


            • 18397
            • 3,250 Posts
            You could also use a Ditto extender. Take a look at the included example extender for more details.