We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36112
    • 24 Posts
    Hi

    I have a page wit a list of products generated by getpage and getresource, with this I have sorted them by a TV called "area". The thing is, I really want to have more "sorting" options.

    It would be nice if customers can choose between sorting items as "price"/"area"/"oranyotherTV"

    Can this be done without having to generate a new template and resource ?

    I was thinking in the lines of a simple link in the top of the page like illustrated below.

    "Sort by: Area, Price, Weight, Volume"

    Any help appreceiated!

    The site in question: http://www.suppli.no/panasonic/

    My getPage call:

    <p class="sortby">Sortert etter: <u>Areal</u>, Pris, Effektfaktor (COP), Varmekapasitet (kW)</p>
    
    [[!getPage?
       &elementClass=`modSnippet`
       &element=`getResources`
     
       &parents=`34`
       &depth=`1`
       &limit=`4`
       &pageVarKey=`page`
    
       &sortbyTV=`areal`
       &sortdirTV=`ASC`
    
       &showHidden=`1`
       &sortby=`{"publishedon":"DESC"}`
    
       &includeTVs=`1`
       &includeContent=`0`
     
       &tpl=`get-produkt-tpl`
    ]]
    
    <ul id="pagination-clean">
    [[!+page.nav]]
    </ul>
      • 3749
      • 24,544 Posts
      You could put the options in a form at the top of the page with the action set to
       [[~[[*id]]]]


      and the method set to 'post'.

      When the page reloads, you could use a custom snippet at the top of the page to read the $_POST info and set a placeholder called 'my_sortby'.

      Then in the snippet tag, use this:

       &sortby=`[[+my_sortby]]`


      In the snippet, something like this:
      <?php
      switch $_POST['sortby'] {
         case 'publishedon':
            $ph = '{"publishedon":"DESC"}';
         // etc.
      }
      $modx->setPlaceholder('my_sortby', $ph);
      return "";
      
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting