We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35082
    • 57 Posts
    This is in my resource field:
    Searchable: [[YesNo? &value=`[[*searchable]]`]]


    This is my snippet code:
    <?php
    /* Code for YesNo Snippet */
    
    If ($value) {
      	$output = 'Yes';
    } else {
      	$output = 'No';
    }
    return $output;
    ?>


    Now when I preview my resource, it displays as "Searchable: Yes"
    It displays as Yes, whether I check or uncheck the searchable option on the settings tab.

    Can't spot what I'm doing wrong here, any help would be appreciated.

    I'm using Revolution 2.2rc3, and reading from chap 7, pg 280 of the MODx official guide.

    Thanks in advance everyone smiley. [ed. note: ironchip last edited this post 14 years, 7 months ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Try 0 and 1 instead of 'yes' and 'no', or else specifically check for 'yes' and 'no',
        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
        • 35082
        • 57 Posts
        Hi Susan,

        It's been a while smiley. I replaced Yes with 1 and No with 0, and same thing happens, the 1 is constantly displayed on front end, whether the box is checked or not.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          What does your TV look like?
            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
            • 35082
            • 57 Posts
            TV? I'm not working with a TV. I'm using the snippet and snippet tag in content field of a newly created resource. [ed. note: ironchip last edited this post 14 years, 7 months ago.]
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Ah. I see the problem. It's a string, so anything will evaluate to true. You'll have to use a specific comparison.

              Hmm... on the other hand, the string '0' is supposed to evaluate to false. [ed. note: sottwell last edited this post 14 years, 7 months ago.]
                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
                • 35082
                • 57 Posts
                Not sure what "specific comparison" to use. Above is the exact sample given in the "official guide" to duplicate. Now I need to stop and go study PHP again smiley..
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Of course! "searchable" is a basic attribute of a resource. MODx can't know which "searchable" TV, resource or custom, you are referring to. Change the name of the TV and it will work as expected.
                    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
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    I should have guessed something was wrong and it wouldn't let me save it with that name; I modified it in the database to test your exact setup.
                      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
                      • 35082
                      • 57 Posts
                      Yes that makes more sense to me, but how do I specify the resource field (searchable) of a particular resource (YesNoDemo)?

                      I thought once this snippet was created, then whatever resource I place the snippet tag in, it should work for that particular resource.