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

Answered Pluralize

    • 40088
    • 708 Posts
    I've been using this snippet in several places to pluralize words when the total number of results returned is greater than one. It works great except for one specific page.
    <?php
    return  $count > 1?  's' : "";

    On the template I use pdoPage to grab all the resources created by a specific user:
    [[!pdoPage@pdoPagination?
        &elementClass=`modSnippet`
        &element=`pdoResources`
        &parents=`0`
        &resources=`-1`
        &where=`{"createdby:=":[[!getUrlParam? &name=`author` &int=`1`]]}`
        &tpl=`authorFilter.html`
        &hideContainers=`1`
        &showHidden=`0`
        &toPlaceholder=`results`
        &totalVar=`total`
        &sortby=`{"publishedon":"DESC"}`
        &sortAlias=`1`
        &limit=`6`
        &pageLimit=`5`
        &pageNavVar=`page.nav`
        &totalVar=`page.total`
    ]]

    Then this to display a message:
    [[!Profile?
        &user=`[[+createdby]]` &useExtended=`1`
    ]]
    [[+member]] has [[!+page.total]] articles[[!pluralFilter? &count=`[[+total]]`]].


    I've compared the problem page with other working pages and don't see any reason why this one page is failing to pluralize.

    This question has been answered by todd.b. See the first response.

      Todd
      • 3749
      • 24,544 Posts
      Should the last placeholder be +page.total?

      Also, you shouldn't need to call the page.total placeholder uncached, since it's being set by the Profile snippet (right?), which is uncached.

      FWIW, being lazy I tend to just use: article(s). wink
        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
        • 40088
        • 708 Posts
        [Laughs] Yeah, using "article(s)" is one option, but I like to understand how things work… or why they don't.

        I already tried
        &count=`[[+page.total]]

        but no change.

        Got rid of the uncached placeholder.
          Todd
          • 3749
          • 24,544 Posts
          Is the page.total extended field set correctly for the user?

          Does the createdby field of the resource hold the ID of the user?
            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
          • discuss.answer
            • 40088
            • 708 Posts
            Turns out the solution was simple (and embarrassing): the call order.

            Moving the pdoPage call before checking for page.total was the fix.

            Thanks @BobRay for the suggestions.
              Todd