New Community Forums are coming. Watch this space for news.

Answered Pluralize

Subscribe: RSS
  • 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
    • 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
        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
      • [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
        • Is the page.total extended field set correctly for the user?

          Does the createdby field of the resource hold the ID of the user?
            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
            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