We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28690
    • 25 Posts
    Hi,
    I am using SimpleSearch and want to put a plural filter on the results message so that it correctly reports "1 Result found..." and "2 Results found...". The message can be modified in the lexicon under the sisea.results_found entry. By default, the message is set to:
    [[+count]] Results found for "[[+text]]"


    My plan was to change it to this:
    [[+count:pluralFilter='Result']] found for "[[+text]]"


    and use this snippet as the custom filter:
    <?php
    $output = $input . " " . $options;  //where $input is the value of [[+count]], $options is "Result"
    if ($input > 1) $output .= "s";
    return $output;
    


    For some reason $input is empty inside the snippet, so I get a message like this for all search results:

    Result found for "search term"

    $options is passed correctly to the flter snippet but I can’t figure out why the value for [[+count]] isn’t. Any suggestions much appreciated.


    Rev 2.05
      • 29668
      • 3 Posts
      Have you checked you’re using backticks ` around the class name you pass to the filter?

      [[+count:pluralFilter=`Result`]] found for "[[+text]]"
        • 28690
        • 25 Posts
        Sorry for the delay getting back on this...

        @Thechuppa - Yes, I have backticks around `Result` (as apposed to what I originally posted).

        `Result` is passed and output correctly, it’s +count that is causing the problem.

        I have double-checked by removing the filter and running the same search and +count works in that case. huh
          • 3749
          • 24,544 Posts
          I don’t know why it’s not working, but I think this would (and it should be faster):

          [[+count]] Result[[!pluralFilter? &count=`[[+count]]`]] found for "[[+text]]"



          /* pluralFilter snippet */
          
          return  $count > 1?  's' : "";
            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
            • 28690
            • 25 Posts
            Thanks Bob, your suggestion works perfectly. Much appreciated.