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

    I want to know if there’s anyway to stop a template variable from working in certain places...I have a template that uses a chunk to format a listing of events; the chunk is programmed to link the images in the list. However, I don’t want all the pictures linked as they don’t all need to link to other pages. If I leave the link entry blank, it goes to mywebsiteurl/[~~], as the chunk has the command <div class="listingpic"><a href="[~[+Link to Page+]~]">[+Listing Pic+]</a></div>. I’d like it to not link at all if I don’t put an entry in to the Link to Page field when creating my pages.

    Is there special input/character/command that could go into the link entry to stop the unnecessary pictures linking?

    Thanks! smiley
      • 33337
      • 3,975 Posts
      -. You can write a snippet, which process the TVs and check to see if they are empty and output accordingly.

      OR

      -. Use PHx, this provides conditionals to alter the output of the placeholders and TVs. eg.
      [+phx:if=`[+myplaceholder+]`:is=``:then=`Output this`:else=``output that`+]
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 25021
        • 3 Posts
        Wow...I was hoping for something a little simpler; haven’t quite made it up to snippet writing just yet :p I’m working on a site that has had MODx installed by a developer - it’s a great system and I’m slowly but surely finding my way around all the features. HTML and CSS I can handle; PHP etc. is all new to me :p

        I’ll find some snippet building tips and try it out...thanks for your help smiley
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          This is basically what you’ll want, something to fetch the TV, check its value and if it’s empty just return nothing, if it’s not empty do something else.

          http://wiki.modxcms.com/index.php/Adding_TV_Widgets_without_hacking_the_core
            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
            • 28554
            • 201 Posts
            It’s actually really simple, as stated above. Here’s what you do:

            - Install PHx from the "Extra’s" section in modxcms.com
            - Create a TV, for example called externalLink
            - In your template, instead of calling [*externalLink*], you call the following:

            [+phx:if=`[*externalLink*]`:is=``:then=``:else=`[*externalLink*]`+]
            


            You can find s’more info about PHx here. You can solve basically any conditional-statement-issue with it, and stuff like date-transforming. I think after Ditto it’s the most important plug-in for MODx. If you need any help let us know smiley, and if the problem is solved and you don’t require any further assistance, please feel free to join my trend of putting [SOLVED] in front of the thread-title (by modifying the title of the first post) to keep this forum in pristine condition wink.
              • 25021
              • 3 Posts
              Thanks guys - this has all been really helpful laugh
                • 4172
                • 5,888 Posts
                there is also a little bit shorter form, which you can try:

                [*externalLink:isnot=``:then=`[*externalLink*]`*]
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!