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

    I need help in something related to output filters, in the case how to output singular or plural based on list output number.

    I have a List TV (single) with the following values:

    Output Values
    [b]N/A||1||2||3||4||5[/b]


    My situation is, if you select option 1 this should output 1 Bedroom, if you select any option grater than 1 should output for example 2 Bedrooms, and if you select N/A should output only the value N/A, without word Bedroom/s.

    I tried something like the code below but it´s not working:
    [[*number-bedrooms:eq=`1`:then=`[[*number-bedrooms]] Bedroom`:gt=`1`:then=`[[*number-bedrooms]] Bedrooms`:else=`[[*number-bedrooms]]`]]


    Any suggestions?

    Many thanks in advance

    This question has been answered by multiple community members. See the first response.

      • 36613
      • 328 Posts
      You can try so:
      [[*number-bedrooms:gt=`1`:then=`[[*number-bedrooms]] Bedrooms`:else=`[[*number-bedrooms]]`]]
        • 16899
        • 284 Posts
        Quote from: cristianb88 at Jul 03, 2013, 08:03 AM
        You can try so:
        [[*number-bedrooms:gt=`1`:then=`[[*number-bedrooms]] Bedrooms`:else=`[[*number-bedrooms]]`]]

        And if i have just 1?! It will output 1 instead of 1 Bedroom!!!!!

        By the way thanks a lot to try to help me.
          • 36613
          • 328 Posts
          I'm not sure though, try this:
          [[*number-bedrooms:gt=`1`:then=`[[*number-bedrooms]] Bedrooms`:else=`[[*number-bedrooms:isequalto=`1`:then=`[[*number-bedrooms]] Bedroom`:else=`[[*number-bedrooms]]`]]`]]
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Output modifiers evaluate both sides of the if-else, even if the first comparison is true. Consider that you only want "Bedroom" if the number is 1, in all other situations you want it to be "Bedrooms". So you might be better off doing something like this:
            [[*number-bedrooms:is=`1`:then=`[[*number-bedrooms]] Bedroom`:else=`[[*number-bedrooms]] Bedrooms`]]
              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
              • 16899
              • 284 Posts
              Quote from: sottwell at Jul 03, 2013, 10:30 AM
              Output modifiers evaluate both sides of the if-else, even if the first comparison is true. Consider that you only want "Bedroom" if the number is 1, in all other situations you want it to be "Bedrooms". So you might be better off doing something like this:
              [[*number-bedrooms:is=`1`:then=`[[*number-bedrooms]] Bedroom`:else=`[[*number-bedrooms]] Bedrooms`]]

              And if i select N/A... Will i have N/A Bedrooms ?
              • discuss.answer
                • 4172
                • 5,888 Posts
                you can try this:

                $output = $plural;
                if ($subject == 'N/A'){
                    $output = '';
                }elseif($subject == '1'){
                    $output = $singular;    
                }
                
                return $output;


                [[*number-bedrooms]] [[checkPlural? &singular=`Bedroom` &plural=`Bedrooms` &subject=`[[*number-bedrooms]]`]]
                [ed. note: Bruno17 last edited this post 13 years, 3 months ago.]
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 22427
                  • 793 Posts
                  ??
                  $output = $subject . ' ' . $plural;
                  if ($subject == 'N/A'){
                      $output = 'N/A';
                  }elseif($subject == '1'){
                      $output = '1 ' . $singular;   
                  }
                   
                  return $output;
                    • 4172
                    • 5,888 Posts
                    Quote from: ottogal at Jul 03, 2013, 12:23 PM
                    ??
                    $output = $subject . ' ' . $plural;
                    if ($subject == 'N/A'){
                        $output = 'N/A';
                    }elseif($subject == '1'){
                        $output = '1 ' . $singular;   
                    }
                     
                    return $output;

                    of course, yes, or like the modified version above.
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                    • discuss.answer
                      • 22427
                      • 793 Posts
                      Or you could create a Custom Output Modifier snippet named SingPlur:
                      $optArray = explode(',',$options);
                      $output = $input . ' ' . $optArray[1];
                      if ($input == 'N/A'){
                          $output = 'N/A';
                      };
                      if ($input == '1'){
                          $output = '1 ' . $optArray[0];  
                      };
                      return $output;

                      Usage:
                      [[*number-bedrooms:SingPlur=`Bedroom,Bedrooms`]]