We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37689
    • 6 Posts
    Hi,
    is it possible to create a Filter function which shows Items related to given parameters ?

    eg show all Products from Producer A which are green colored ?

    Or something like this example:
    http://processwire.com/skyscrapers/

    Is therer any tutorial or example around whith this functionality, please?
    ?
      • 3749
      • 24,544 Posts
      Yes, there are many ways to do that in MODX. The method depends on how you are storing the data, though, so we need more information from you in order to help.
        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
        • 37689
        • 6 Posts
        I havent started with Modx yet , I am still evaluating Systems to find the best suited for me.

        So a simpel example so that I can compare the approach to another CMS would be lovely..

        Thank You for Your answer !
        Marc
          • 3749
          • 24,544 Posts
          Typically, you'd have the HTML for the output in a Tpl chunk with placeholders for the values (lets call it 'ProductTpl'):

          <h3>[[+product_name]]</h3>
          <p>Price: [[+product_price]]</p>
          <p>Size: [[+product_size]]</p>

          The best method, if you're going to have many product pages, is to use a custom DB table to hold the data, and use xPDO to interact with it.

          That would look something like this:

          $output = '';
          $products = $modx->getCollection('modProduct');
          
          foreach($products as $product) {
              $fields = $product->toArray();
              $output .= $modx->getChunk('ProductTpl', $fields);
          }
          return $output;


          This requires some work up front to create the table and generate the xPDO class and map files.

          The quick-and-dirty alternative, if you won't have a lot of products would be to create a separate resource for each product and put the data for the product in the resource's fields and create Template Variable (TVs) to hold any data that won't fit in the resource fields.

          This is much slower, but easy to set up fairly quickly and the output (using the same Tpl chunk) would be created with a single call to the getResources snippet.

          [[getResources? &tpl=`ProductTpl` . . . ]]
            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
            • 37689
            • 6 Posts
            Hi,
            so essentially I have to use xPDO to select the data according the the submitted form Parameters.

            Thank you very much!

            Cheers
            Marc
              • 3749
              • 24,544 Posts
              That would be by far the fastest in terms of page-load times. The second method would not require any explicit use of xPDO on your part.

              There is also a sort of hybrid method that's relatively easy that's described here: http://bobsguides.com/blog.html/2014/06/02/why-extend-modresource/
                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
                • 40045
                • 534 Posts
                To easily manage a custom table, have a look at MIGX (package) and MIGXDB specifically which also helps in creating the tables etc. if you have set up your custom table xml schema!