We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49300
    • 19 Posts
    If Template ID is equals to ['#'] then [[$chunk]]

    I want a simple task:

    To display a chunk for a certain template.

    How to do it?

    Display a chunk based on ID, I know:

    [[*id:is=`1`:then=`[[$thischunk]]`]]

    This question has been answered by sottwell. See the first response.

      • 19872
      • 1,078 Posts
      Maybe template [[*template]]

      [[*template:is=`1`:then=`[[$thischunk]]`]]
        • 19872
        • 1,078 Posts
        http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/commonly-used-template-tags


        Always curious and wanting to learn new tricks, in what scenario would you want a chunk to load because of the template. Why not just put the chunk on the template to begin with?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          [[[[*template:is=`1`:then=`$thischunk`]]]]


          The way you had it written would cause MODX to prepare the chunk even if it wasn't used. This way, the output of the modifier will be the chunk tags, which MODX will process on the next pass through the parser.
            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
            • 19872
            • 1,078 Posts
            Hey Susan: I've noticed you writing these this way before and now I know why. Very good to know.

            Quote from: sottwell at Mar 03, 2015, 09:09 PM
            [[[[*template:is=`1`:then=`$thischunk`]]]]


            The way you had it written would cause MODX to prepare the chunk even if it wasn't used. This way, the output of the modifier will be the chunk tags, which MODX will process on the next pass through the parser.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
                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
                • 49300
                • 19 Posts
                [[[[*template:is=`1`:then=`$thischunk`]]]]


                this doesn't work for me. and to @sottwell, are you saying that this is a bad practice?

                The problem I'm having is that I need to put a share button on several pages. Those pages are under a template so I thought getting the template will make my life easier.

                The workaround for me right now is to get the parent ID of those pages instead of the template.

                It works fine but I thought getting the template ID is best.
                  • 19872
                  • 1,078 Posts
                  Why not put the button in a chunk, and call it on the page using a TV selector?

                  TV
                  Input Type: Checkbox
                  OK to leave blank: Yes

                  Input value:
                  Show Share Button on This Page==[[$yourShareButtonChunkName]]

                  Output Value (leave blank) unless you want it to appear in more instances than not: then put the chunk call in this field.

                  Output: Default
                  • discuss.answer
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    It should work. Are you changing the `1` to be the ID of the template in question? Of course using parent will also work, as long as they are all the children of that particular parent.
                      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
                      • 19872
                      • 1,078 Posts
                      On your template put the name of your TV selector

                      [[*myShareButton_selector]]