We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32678
    • 290 Posts
    I'm returning pdoResources results to a two-column unordered list, and need the results to stack rather than list side-by-side. There are CSS hacks for this, but then I'd also have to hack the framework so separate snippet calls seems easier. Right.

    The first call outputs 1-6, the second 6+. The second call returns the full list of results, though...
    [[!pdoResources?
    &parents=`[[*parent]]`
    &depth=`1`
    &showHidden=`1`
    &tplCondition=`menuindex`
    &tplOperator=`isgreaterthan`
    &conditionalTpls=`{"6":"guide_footerMenuItem"}`
    &tpl=`guide_footerMenuItem`
    &sortby=`{"menuindex":"ASC"}`
    &includeTVList=`pagetitle,longtitle,id`
    &tvPrefix=``
    ]]


    Is it the tplCondition, tplOperator, or both, causing this? Based on a couple example usages for these params found on the forum, I thought this would be OK, but obviously not.

    A separate but related question -- I tried the above using &idx, which "indicate[s] the initial number of iteration for result output", but the call returns the full list of results. Do I have the wrong idea about &idx? Here's that call:
    [[!pdoResources?
    &parents=`[[*parent]]`
    &depth=`1`
    &showHidden=`1`
    &idx=`7`
    &tpl=`guide_footerMenuItem`
    &sortby=`{"menuindex":"ASC"}`
    &includeTVList=`pagetitle,longtitle,id`
    &tvPrefix=``
    ]]


    Ultimately, I got this to work:
    [[!pdoResources?
    &parents=`[[*parent]]`
    &depth=`1`
    &showHidden=`1`
    &tvFilters=`menuindex>>5`
    &tpl=`guide_footerMenuItem`
    &sortby=`{"menuindex":"ASC"}`
    &includeTVList=`pagetitle,longtitle,id`
    &tvPrefix=``
    ]]


    What I don't like about any of these approaches is that they're not dynamic. It would be great to include this in the template such that it breaks the results in half using &limit=totalVar/2 or something. Assuming this level on conditional would require a custom snippet, though...
      • 3749
      • 24,544 Posts
      You would need a custom snippet, but I think it be at the top and could just calculate the split number and set placeholders for two $tvFilters properties.

      This is off the top of my head, so probably wrong.

      $parent = $modx->resource->get('parent');
      $count = $modx->getCount('modResource', array('parent' => $parent));
      
      $split = floor($count/2);
      
      $modx->setPlaceholder('splitOne', (int) $split + 1);
      $mod->setPlaceholder('splitTwo', (int) $split);
      

      Then in the first call:

      &tvFilters=`menuindex<<[[+splitOne]]`


      In the second:

      &tvFilters=`menuindex>>[[+splitTwo]]`


      Note that this will only work if all the resources are immediate children of the parent resource. If there are grandChildren, you'd have to do it with getChildIds().

      $cids = $modx->getChildIds($parent);
      $count = count($cids);


        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Couldn't you just get the count, divide it by two, and have the first call limit by that number, and the second call offset by that number?
          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
          • 3749
          • 24,544 Posts
          That should work too if pdoResources has an offset property. You'd still have to set a placeholder.
            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
            • 37105
            • 194 Posts
            A separate but related question -- I tried the above using &idx, which "indicate[s] the initial number of iteration for result output", but the call returns the full list of results. Do I have the wrong idea about &idx?
            As far I can see pdoResources is ingoring the &idx setting completely. In my case I want to set the idx to '0' for a slider to work, but still starts at default value of '1'. My workaround is to use an output filter on the idx placeholder.
            [[+idx:decr]]

            I am using the latest pdoTools (2.1.12-pl) and just filed a bug to Bezumkin on Github (https://github.com/bezumkin/pdoTools/issues/163).

            Maybe this problem will be solved so you will be able to use the &idx=`7` setting as starting point.
              Codeplaza Webdesign: for professional websites at low cost
              • 37105
              • 194 Posts
              Just for your info: today new version of PDO Tool released with fix of ignored &idx.

              See https://raw.githubusercontent.com/bezumkin/pdoTools/master/core/components/pdotools/docs/changelog.txt for the release notes smiley
                Codeplaza Webdesign: for professional websites at low cost