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

    I managed to sort the getResources results by "product_type".

    How can I do this (the results are divided in separate div's according to "product_type":

    <div> PRODUCT TYPE A


    ...
    ....

    </div>

    <div> PRODUCT TYPE B


    ...
    ....

    </div>

    <div> PRODUCT TYPE C


    ...
    ....

    </div>



    [[!getResources?
    &includeContent=`1`
    &includeTVs=`1`
    &processTVs=`1`
    &tpl=`product_navigation_left_main_TPL`
    &parents=`7`
    &limit=`0`
    &sortbyTV=`product_type`
    &sortdirTV=`ASC`
    ]]


    Regards

    This question has been answered by sottwell. See the first response.

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      As far as I know, you can't. You'll need a different getResources snippet call for each section.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 47717
        • 144 Posts
        Quote from: sottwell at Feb 08, 2016, 06:57 AM
        As far as I know, you can't. You'll need a different getResources snippet call for each section.

        Hi,

        That's a bummer !

        The "product_types" are actually "tags" that the client fills in, so I don't know how much there will be.

        So how can I make a different "getResources" call for each "product_type", as I don't know what they will be ? sad
        • discuss.answer
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Use a snippet that reads the tags, and for each one sets up $modx->runSnippet('getResources'...)

          You can have it generate the heading from the tag and set it as a placeholder, and set the output of the getResources run as a placeholder as well. That way you can use a chunk to lay it all out.

          There's probably a better way to handle the whole situation, but this is what comes to mind right now.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 47717
            • 144 Posts
            Quote from: sottwell at Feb 08, 2016, 10:55 AM
            Use a snippet that reads the tags, and for each one sets up $modx->runSnippet('getResources'...)

            You can have it generate the heading from the tag and set it as a placeholder, and set the output of the getResources run as a placeholder as well. That way you can use a chunk to lay it all out.

            There's probably a better way to handle the whole situation, but this is what comes to mind right now.

            Hi Sottwell,

            You sure got me on the right track !

            Now it is solved. For people wanting to use this code :

            1. Install "tagLister"

            2. Make all "tags" appear, in your own TPL :


            [[!tagLister? &tv=`product_type` &tpl=`product_type_tpl`]]


            3. The TPL in which EACH "tag" will be put : product_type_tpl.
            Each "tag" will be used as input for a getResources call that is filtered with that tag


            <section class="tagpart"><h3>[[+tag]] ([[+count]])</h3>
            
            [[!getResources?
            &debug=`1`
            &includeContent=`1`
            &includeTVs=`1`
            &processTVs=`1`
            &tpl=`product_navigation_left_main_TPL`
            &parents=`7`
            &limit=`0`
            &tvFilters=`product_type==[[+tag]]`
            
            
            ]]
            
            </section>


            4. Now that last getResources call, gets it's separate results (=titles which link to their pages) in it's own Template: product_navigation_left_main_TPL

            <a href="[[~[[+id]]]]" title="De Bruyne: info [[+pagetitle]] | product by [[+tv.product_leverancier]] for [[+tv.product_type]]" class="[[+tv.product_leverancier:replace=` ==-`]]" id="[[+tv.product_type:replace=` ==-`]]" >[[+pagetitle]]</a>