Hide empty template variable

Hi Guys,

I’d like to hide the output of a template variable when the field is left empty in the resource TV field. In this case, the output of the template variable is a link button and the TV is a URL.

I’ve checked online and the docs and found the Modx IF statement which I am unsure how to use. The template variable name is [[*website_link]]. Could anyone guide me on using this please?

https://docs.modx.com/current/en/extras/if/index

[[If?
   &subject=`[[*hidemenu]]`
   &operator=`EQ`
   &operand=`1`
   &then=`This resource is not visible in the menu.`
   &else=`This resource shows up in the menu in spot [[*menuindex]].`
]]

I would use an Output filter.

[[*hidemenu:eq=`1`:then=`This resource is not visible in the menu.`:else=`This resource shows up in the menu in spot [[*menuindex]].`]]

https://docs.modx.com/3.x/en/building-sites/tag-syntax/output-filters

With the IF extra:

[[If?
   &subject=`[[*website_link]]`
   &operator=`notempty`
   &then=`<a href="[[*website_link]]">Website</a>`
]]

With an output modifier:

[[*website_link:notempty=`<a href="[[*website_link]]">Website</a>`]]
1 Like