We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47308
    • 68 Posts
    I've been using MODX for sometime now and have recently discovered conditional tags. I can't find any mention of them in the official documentation and only found out about them through this forum. Where did I miss this in the docs?

    Additionally, will a simple conditional statement create a noticeable performance hit? I have a number of optional TVs in this template and I'm not sure I want to create a snippet for each one.

    Thanks. [ed. note: hhk222 last edited this post 9 years, 10 months ago.]
      • 47717
      • 144 Posts
      Quote from: hhk222 at Nov 15, 2016, 06:52 AM
      I've been using MODX for sometime now and have recently discovered conditional tags. I can't find any mention of them in the official documentation and only found out about them through this forum. Where did I miss this in the docs?

      Additionally, will a simple conditional statement create a noticeable performance hit? I have a number of optional TVs in this template and I'm not sure I want to create a snippet for each one.

      Thanks.

      https://docs.modx.com/extras/revo/if

      or use the built in "output modifiers": https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers)
        • 47308
        • 68 Posts
        Quote from: sriananda at Nov 15, 2016, 07:47 AM
        Quote from: hhk222 at Nov 15, 2016, 06:52 AM
        I've been using MODX for sometime now and have recently discovered conditional tags. I can't find any mention of them in the official documentation and only found out about them through this forum. Where did I miss this in the docs?

        Additionally, will a simple conditional statement create a noticeable performance hit? I have a number of optional TVs in this template and I'm not sure I want to create a snippet for each one.

        Thanks.

        https://docs.modx.com/extras/revo/if

        or use the built in "output modifiers": https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers)

        I thought the conditional statements were supported in the core code. I guess that's why my statements weren't working. I don't have the IF extra installed.

        Will take a look at output modifiers. Can the output modifier return a null if the TV is empty? Are they more efficient than using the IF extra?

        Thanks.
          • 44922
          • 131 Posts
          You could create your own snippet and run the logic there from the TVs, then output the results as placeholders. That might have less of a hit than calling a bunch of 'If' snippets or conditional output modifiers...
            • 3749
            • 24,544 Posts
            Additionally, will a simple conditional statement create a noticeable performance hit? I have a number of optional TVs in this template and I'm not sure I want to create a snippet for each one.

            1. Yes.
            2. It's likely that you could do it with a single snippet.

            Can you give us more information about what you're trying to do?
              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
              • 47308
              • 68 Posts
              Quote from: BobRay at Nov 15, 2016, 11:10 PM
              Additionally, will a simple conditional statement create a noticeable performance hit? I have a number of optional TVs in this template and I'm not sure I want to create a snippet for each one.

              1. Yes.
              2. It's likely that you could do it with a single snippet.

              Can you give us more information about what you're trying to do?

              I have a template for a product. For product detail, I have them displaying in an accordion panels below the general description. I have a maximum of 4 accordions but not every product needs all 4. If I leave the content and title of an accordion empty, it shows the empty box. I would prefer it not show the box at all.

              This is the code I came up with:

              [[*accordion_title:is=``:then=``:else=`
              									<div class="panel panel-default">
              										<div class="panel-heading">
              											<h4 class="panel-title">
              												<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse1Two">
              													[[*accordion_title]]
              												</a>
              											</h4>
              										</div>
              										<div id="collapse1Two" class="accordion-body collapse">
              											<div class="panel-body">
              												<p>[[*accordion_content]]</p>
              											</div>
              										</div>
              									</div>
              								`]]
              


              The panel DIV only shows if there is something in the accordion_title TV.

              This works but I'm wondering if there is a better way.
                • 3749
                • 24,544 Posts
                As a snippet, it would look like this:

                [[!AccordionTitle? &value=`[[*accordion_title]]` ]]
                

                /* AccordianTitle snippet */
                
                $title = $modx->getOption('value', $scriptProperties, '');
                
                if (empty($title)) {
                    $output = '';
                } else {
                    $output = '
                                                    <div class="panel panel-default">
                                                        <div class="panel-heading">
                                                            <h4 class="panel-title">
                                                                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse1Two">
                                                                    [[*accordion_title]]
                                                                </a>
                                                            </h4>
                                                        </div>
                                                        <div id="collapse1Two" class="accordion-body collapse">
                                                            <div class="panel-body">
                                                                <p>[[*accordion_content]]</p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                '
                }
                
                return $output;


                I'm not sure it would work, but if it does, it would be significantly faster.
                  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