We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37550 ☆ A M B ☆
    • 711 Posts
    Hi,

    I’ve been trying to work out for a while now how to create a drop down option on my ditto page.

    Basically I have a Category TV which is a drop down option I would like to be able to allow the user to filter the page results based on the category they select?

    Has anyone managed to do this before?

    For example my Category TV contains

    Library==Library||
    Leisure==Leisure||
    Police==Police||
    Postoffice==Postoffice||
    Shopping==Shopping||
    Transport==Transport||
    Parking==Parking||
    Play Area==Play Area||
    Toilets==Toilets||

    And therefor the dropdown option on the page should allow the user to filter on

    Library
    Leisure
    Police
    Postoffice
    Shopping
    Transport
    Parking
    Play Area
    Toilets

    Thanks Aaron

      http://www.onesmarthost.co.uk
      UK MODX Hosting with love.
      • 22827
      • 129 Posts
      Did you figure this out?

      The ditto tags placeholder only shows the tags available for the current document, it would be handy if it had a place holder for the list page that would be replaced with a list+chunk of available tags.
        • 26931
        • 2,314 Posts
        Hi,

        maybe TVeditor & TVexplorer?

        jan
          • 37550 ☆ A M B ☆
          • 711 Posts
          I managed to work it out in the end, I did initially look at tvExplorer but not sure if it was me but it looked rather complex.

          In the end I added &tagData=`Stay-Category` to the ditto call.

          and above the ditto call, called my filter snippet [[cat-filter?tvName=`Facility-Category`]]


          <?php
          // Get Vars passed in snip query
          $tvName = (isset($tvName))? $tvName : "Facility-Category";

          $sql = $modx->db->query(’SELECT value FROM modx_site_tmplvars, modx_site_tmplvar_contentvalues WHERE name= "’ .$tvName .’" AND modx_site_tmplvars.id = modx_site_tmplvar_contentvalues.tmplvarid GROUP BY value ’);

          $va_result = $modx->db->makeArray($sql);

          $selected = $_GET[’tags’];

          $words ="";
          foreach ($va_result as $row){
          $words .= trim(str_replace (’||’ , ’,’, $row[value])) .’,’;
          }

          $va_words = explode(",", $words); // convert to a array
          $answer = array_unique($va_words ); // remove duplicates

          foreach ($answer as $row) {
          if (!empty($row)) {
          $options .= ’<option value="’ .$row .’"’;
          if ($selected == $row) {
          $options .= ’ selected’;
          }
          $options .= ’>’ .$row .’</option>’ ."\n";
          }
          }

          $modx->setPlaceholder("lstOptions", $options);
          $result = $modx->mergeChunkContent("{{Search-Filter}}")."\n";

          return $result;
          ?>

          And the chunk it uses is:

          Search-Filter

          <script>
          function copyToAction(val){
          document.frmFilter.action = document.frmFilter.action + val
          }
          </script>
          Category: <form name="frmFilter" method="post" action="?tags=">
          <select name="select" onblur="copyToAction(this.value);">
          <option value="">Show all</option>
          [+lstOptions+]
          </select>
          <input type="submit" name="Submit" value="Submit">
          </form>

          There’s probably lots of room for improvement above, but it has got me going for now. smiley

          Thanks Aaron
            http://www.onesmarthost.co.uk
            UK MODX Hosting with love.
            • 20413
            • 2,877 Posts
            Tnx! Nice!!  smiley REALLY NICE!!!!!!!
              @hawproductions | http://mrhaw.com/

              Infograph: MODX Advanced Install in 7 steps:
              http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

              Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
              http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
              • 37550 ☆ A M B ☆
              • 711 Posts
              Cool no problem, I kind of panicked when seeing a thread reply in my email I was thinking someone is going to tell me it’s already done or there is an easier way smiley

              At least my client is happy with the above for now.

              Aaron.
                http://www.onesmarthost.co.uk
                UK MODX Hosting with love.
                • 25132
                • 129 Posts
                Hi Aaron

                Thanks for putting up your code. It seems to be exactly what I’m looking for. Have a long list of venues for a festival and want users to be able to search by venue without having to create separate documents with individual ditto filter calls for each venue. However, I am a little confused about your two tv references: Stay-Category and Facility-Category. Which one is the original Category list you mention earlier in your thread and which one is new? And what’s the set-up of the new category? Or what am I getting wrong? I know this is an old thread but perhaps I’m lucky and you are still subscribed to it and can help me out.

                Thanks!