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

    I have a div in a template and I want to show this div when the page id is 1 & 95.

    Currently I am doing something like this but it is not working:

    				[[*id:is=`1`,`95`:then=``:else=`
    					<div class="breadcrumb"> [[BreadCrumb]] </div>
    				`]]


    This is not working. Sorry but I am new to modx.
      • 22840
      • 1,572 Posts
      Not sure if it will work but try:

      [[*id:is=`1,95`:then=``:else=`
          <div class="breadcrumb"> [[BreadCrumb]] </div>
      `]]
        • 43965
        • 23 Posts
        No didn't work. tried that already. thanks for your help.

        Quote from: paulp at Aug 16, 2013, 10:51 AM
        Not sure if it will work but try:

        [[*id:is=`1,95`:then=``:else=`
            <div class="breadcrumb"> [[BreadCrumb]] </div>
        `]]
          • 38290
          • 712 Posts
          How about
          [[[[*id:is=`1`:or=`95`:then=`$breadcrumb`]]]]
          


          With a breadcrumb chunk
          <div class=breadcrumb>[[Breadcrumb]]</div>
          
            jpdevries
            • 43965
            • 23 Posts
            Thanks for your help. I am doing the following, thought it is not working :

            				[[*id:is=`1`:or=`95`:then=``:else=`
            					<div class="breadcrumb"> [[BreadCrumb]] </div>
            				`]]


            Quote from: dinocorn at Aug 16, 2013, 11:41 AM
            How about
            [[[[*id:is=`1`:or=`95`:then=`$breadcrumb`]]]]
            


            With a breadcrumb chunk
            <div class="breadcrumb">[[Breadcrumb]]</div>
            
              • 3749
              • 24,544 Posts
              This is calling a snippet called 'BreadCrumb'.

              [[*id:is=`1`:or=`95`:then=``:else=`
                  <div class="breadcrumb"> [[BreadCrumb]] </div>
              `]]


              Do you have a snippet with that exact name? If you're trying to show a Chunk or Template Variable with that name, you'll have to tell us what version of MODX you're using so we can advise you.
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                There is a reason why dinocorn has that particular structure; i.e. the doubled-up tags around the conditional, and no tags inside. The way yours is, MODx will see the snippet and process the snippet before the condition is even tested. So whether it's to be displayed or not, the snippet is still processed.

                By having the output of the conditional be just the snippet (or chunk) name, so that the tags aren't inside the conditional, what you get is an empty set of tags if the condition is false, and the set of tags with the snippet (or chunk) name if it's true.
                [[[[id:is=`1`:or=`95`:then=``:else=`Breadcrumb`]]]]

                will produce [[]] if either of the first two conditions are true, or [[Breadcrumb]] if they are both false. MODx simply removes the empty tags.

                This way the snippet is only run if the resource is not #1 or #95.

                Jason explains it a lot better here http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/
                  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
                  • 43965
                  • 23 Posts
                  thanks to all for your help. However I is still not working.

                  In the template I changed the code to ---> [[[[*id:is=`1`:or=`95`:then=`$breadcrumb`]]]]

                  Then i created a chunk named breadcrumb and in this chunk i included the following code ---> <div class="breadcrumb">[[Breadcrumb]]</div>

                  I am using modx revolution and this is not working. The breadcrumbs has vanished from all of the pages.


                  Quote from: sottwell at Aug 16, 2013, 10:29 PM
                  There is a reason why dinocorn has that particular structure; i.e. the doubled-up tags around the conditional, and no tags inside. The way yours is, MODx will see the snippet and process the snippet before the condition is even tested. So whether it's to be displayed or not, the snippet is still processed.

                  By having the output of the conditional be just the snippet (or chunk) name, so that the tags aren't inside the conditional, what you get is an empty set of tags if the condition is false, and the set of tags with the snippet (or chunk) name if it's true.
                  [[[[id:is=`1`:or=`95`:then=``:else=`Breadcrumb`]]]]

                  will produce [[]] if either of the first two conditions are true, or [[Breadcrumb]] if they are both false. MODx simply removes the empty tags.

                  This way the snippet is only run if the resource is not #1 or #95.

                  Jason explains it a lot better here http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/
                    • 43965
                    • 23 Posts
                    Issue has been fixed. We were missing the shockedr:is in the code

                    [[*id:is=`1`:or:is=`95`:then=``:else=`
                        <div class="breadcrumb"> [[BreadCrumb]] </div>
                    `]]


                    Thanks to all for your help
                      • 3749
                      • 24,544 Posts
                      Try this in the chunk (unless you've changed the name of the Breadcrumbs snippet):

                      <div class="breadcrumb">[[Breadcrumbs]]</div>


                      You might have to call the snippet uncached to get the right output:

                      <div class="breadcrumb">[[!Breadcrumbs]]</div>



                      FYI, I would do it this way (with a custom snippet) to speed things up:

                      [[!MyBreadCrumbs]]




                      /* MyBreadCrumbs snippet */
                      
                      $id = $modx->resource->get('id');
                      
                      if ( ($id == 1) || ($id == 95) ) {
                         return $modx->runSnippet('Breadcrumbs');
                      } else {
                         return '';
                      }
                        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