We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5091
    • 332 Posts
    If this question has been asked, please forgive me and please kindly point me to the thread - I couldn’t find anything from forum search.

    I have a section called ’callout’ and the div wrap is always the same

    <div class="callout">
       <div class="callout_btm">
       </div>
    </div>


    I want to serve it as a wrapper for callout items that will be used in some pages, but not all.

    I thought of creating a TV and placed in the template (the callout divs can go to chunk if necessary)
    <div class="callout">
       <div class="callout_btm">
    [*callout*]
       </div>
    </div>


    But if no items are placed in the callout TV, it will still show the
    <div class="callout">
    <div class="callout_btm">
    </div>

    in the source code. I don’t want that.

    How can I have it removes if no item in the callout TV in a page?

    Thanks!



      • 33719
      • 33 Posts
      hi,

      very interesting question, i was asking myself how to achived this with modx ... (It’s very easy with smarty).

      huh
        • 27330
        • 884 Posts
        you could keep the whole wrapper in a chunk, then decided with PHx to show it only if the TV has value.

        check this
        http://wiki.modxcms.com/index.php/PHx#ifempty.3D.60other_value.60

          • 29181
          • 480 Posts
          I agree I would either use PHx

          [+phx:if=`[*callout*]`:isnot=``:then=`<div class="callout">
             <div class="callout_btm">
          [*callout*]
             </div>
          </div>`:else=`<p>No callout data specified</p>`+]


          may work for you. More information about can be found at http://wiki.modxcms.com/index.php/PHx/CustomModifiers

          Taff
            Adrian Lawley: www.adrianlawley.com
            • 33719
            • 33 Posts
            good, thanks guys.

            I though of the snippet solution, but didn’t found it very smart.
            Phx solution is not very smart compared to the smarty syntax but is ok for the moment.

            Another solution ?
              • 27330
              • 884 Posts
              do you look for a way to do it or to be a smartass?

              just kidding smiley
              PHx seems very ’smart’ to me, at least very flexible I think.
              what don’t u like in the phx way?
                • 33719
                • 33 Posts
                do you look for a way to do it or to be a smartass?

                just kidding wink

                ;) I’m new to modx, and i think it’s important to focus on using it the best way.

                Ain’t it better like that ?
                {if $var}<p>{$var}</p>{/if}
                (smarty code). No big differences, ok. But to me it is, mostely because i used it a lot.

                But that’s ok with PHx.
                  • 27330
                  • 884 Posts


                  <?php
                  if (trim($output) != ’’) {
                  return $options;
                  }
                  ?>

                  I hear what you say, it’s hard to adopt to a new system smiley
                  but keep PHx in your bookmark, you’ll be surprised how many times it can help you do things you just have to have.
                  I use it in almost every modx site I’ve done. the best addon to modx after Ditto IMHO.


                    • 5091
                    • 332 Posts
                    Thank you so much Taff and Sinbad.

                    ___seb, you can use smarty when v0.97 comes out smiley

                    Taff, just wanting to let you know, your code works beautifully.

                    I have this:
                    [+phx:if=`[*callout*]`:isnot=``:then=`<div class="callout">
                    <div class="callout_btm">
                    [*callout*]
                    </div>
                    </div>`:else=``+]

                    This new tricks makes me love Modx even more grin
                      • 29181
                      • 480 Posts
                      I’m glad it works. As seb mentioned it may not be the tidiest solution but it works. If you want a something more smarty orientated then you should create a snippet that returns the output with the aid of http://modxcms.com/gettemplatevaroutput.html or one of the other template variable output.

                      <?php//an untested something
                      $tvString="callout";
                      $tv = $modx->getTemplateVarOutput($tvString);
                      if (trim($tv[$tvString]) != '') {
                       $output= "<div class=\"callout\">
                         <div class=\"callout_btm\">".
                      $tv[$tvString]."
                         </div>
                      </div>";
                      return $output;
                      }
                      
                      ?>


                      Something like this would probably work (I haven’t tested it) Find out more about the API at http://wiki.modxcms.com/index.php/Category:API

                      As always with MODx you could spend all day finding different ways to skin a cat...I would go with the bowie knife solution (fastest) unless things started getting hard to track (which is possibly PHx’s downfall).

                      Good luck,
                      Taff
                        Adrian Lawley: www.adrianlawley.com