We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34699
    • 5 Posts
    Hello.
    I would like a part of my html-code will only be shown if a certain TV isn’t empty.
    Therefor I installed the "If"-add-on and modified the code example like this:

    [[!If? 
    &subject=`[[*name]]` 
    &operator=`notempty` 
    &then=`<div>my html-code</div>` 
    &else=``
    ]] 
    


    (I tried with &else=`0`, &else=`empty` and without &else as well)

    It doesn’t work and I get out the code part after the TV, like this
    > operator=`notempty` &then=`<div>my html-code</div>`...


    Who can help me with that?

    Thank you
    Dick
      • 6228
      • 249 Posts
      With built-in output filters, I’m not sure why there would be a need for an [tt]If[/tt] add-on.

      Anyhoo, try this:
      [[*name:notempty=`<div>my html-code</div>`]]
        lo9on.com

        MODx Evolution/Revolution | Remote Desktop Training | Development
        • 24068
        • 4 Posts
        Quote from: dick at Jun 04, 2011, 10:47 AM

        [[!If? 
        &subject=`[[*name]]` 
        &operator=`notempty` 
        &then=`<div>my html-code</div>` 
        &else=``
        ]] 
        


        Try

        [[!If? 
        &subject=`[[*name]]` 
        &operator=`notempty` 
        &then=`<div>my html-code</div>` 
        &else=``]] 
        


        Avoiding the last new-line solved this for me.
          • 1343 ☆ A M B ☆
          • 2,213 Posts
          Quote from: cyclissmo at Jun 04, 2011, 11:44 AM

          With built-in output filters, I’m not sure why there would be a need for an [tt]If[/tt] add-on.

          Anyhoo, try this:
          [[*name:notempty=`<div>my html-code</div>`]]


          If I recall correctly "IF" is actually more efficient on this front.
            Patrick | Server Wrangler
            About Me: Website | Tweets |  MODX Hosting
            • 34699
            • 5 Posts
            Thank you for your help.
            cyclismo, I tried your solution and it works perfectly!
            But as an absolute modx newbie: Where do I get information about this kind of solutions?
            How do I know to use
            [[*name:notempty=`<div>my html-code</div>`]]
            instead of using
            [!If?...
            ?
              • 33968
              • 863 Posts
                • 34699
                • 5 Posts
                Thank you, lucas, for your hint.
                That answers a lot of my open questions (I hope).
                May the next rainy days come...
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  Try caching that If snippet call.

                  [[If ..]] instead of [[!If ]]

                  There’s no need for it to be processing every request if the data wont change before the cache get clears anyway.
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.