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

    I have a setup on a site I'm developing that requires returned resources to be automatically split into chunks of three, eg:

    <ul class="bucket">
    <li id="resource1">Resource 1</li>
    <li id="resource2">Resource 2</li>
    <li id="resource3">Resource 3</li>
    </ul>
    <ul class="bucket">
    <li id="resource4">Resource 4</li>
    <li id="resource5">Resource 5</li>
    <li id="resource6">Resource 6</li>
    </ul>

    I've done this with Evo and Ditto before using this snippet: http://modx.com/extras/package/dittoformat, but I'm not aware of an equivalent for Revo. Any thoughts?
      • 33968
      • 863 Posts
      You could look at using &tpl_3 to do that, perhaps something like:
      <li>[[+pagetitle]]</li>
      </ul>
      <ul>
      

      You'll also need to use the &tplLast property (assuming &tplLast overrides &tpl_3). That could just be the same chunk you are using for &tpl and would prevent the extra </ul><ul> being added in case your resource list ends as a multiple of three.

      So we have:
      [[!getResources? &tpl=`tplChunk` &tplLast=`tplChunk` &tpl_3=`tpl3Chunk`]]
      

      Does that work?
        • 36521
        • 9 Posts
        Thanks - that works (as long as I add a closing </ul> to tplLast), but only for the first two groups, since &tpl_N is just applied to resource N, not every Nth resource. Since I know the number of resources in this case and it won't be changing, I'm going to just use tpl_3, tpl_6, tpl_9 and so on in this case, but I'm wondering if there's a more scalable way to do this.
          • 33968
          • 863 Posts
          Ahh, sorry I had wrongly assumed that &tpl_N applied to every multiple of N... rather than just N. I would have thought for a looping snippet it would be more useful that way. Feature request maybe.

          Otherwise I think it might be possible to loop over your list items with a custom output filter...
            • 3749
            • 24,544 Posts
            How are the resources selected, and what fields to you need to show? A fairly simple custom snippet might do it.

            Is the total number a multiple of 3, or might there be odd ones at the end?
              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
              • 36521
              • 9 Posts
              The number's variable. In some cases it might be an even multiple of 3, and in others not.

              As for the fields, I'm using the page title, url, and an image template variable.
                • 3749
                • 24,544 Posts
                How are the resources selected?
                  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
                  • 33968
                  • 863 Posts
                  In other words, what getResources call would you use to retrieve those documents? Parents, filters, tvs, etc...
                    • 36521
                    • 9 Posts
                    Right now the call looks like this:

                    [[!getResources?&parents=`[[*parent]]`&tpl=`drawerTpl` &tplLast=`drawerLastTpl` &tpl_3=`drawer3Tpl` &tpl_6=`drawer3Tpl` &tpl_9=`drawer3Tpl` &includeTVs=`1` &processTVs=`1` &tvPrefix=`` &limit=`0` ]]

                      • 37059
                      • 368 Posts
                      Do I take it correctly that you are grouping the resources based on some factor such as the value of a TV? If so, I am also interested in any ideas for this - last year I encountered a similar problem and was reduced to writing a rather heavy custom script with extra tables...
                        Jason