Home › Toolset Professional Support › [Resolved] Hide field when empty using conditional HTML
Problem:
I've managed to get a field to only show if NOT empty.
The trouble is that it's not outputting the field data, just the code as is written (i.e. [types field='display-date-to.... etc.) in the front end.
Solution:
The client have found that the issue was the Raw HTML block wasn't displaying correctly. When changed to a WP Custom HTML block, it worked as intended!
Relevant Documentation:
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Hong_Kong (GMT+08:00)
Tagged: Content Templates, Views plugin
Related documentation:
This topic contains 3 replies, has 2 voices.
Last updated by Luo Yang 6 years, 1 month ago.
Assisted by: Luo Yang.
Tell us what you are trying to do? Hide a 'Date to' field when empty
Is there any documentation that you are following? Yes - https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ and https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/
Is there a similar example that we can see? As above
What is the link to your site? sobell.adstest.co.uk
I've managed to get a field to only show if NOT empty using the following:
[wpv-conditional if="( NOT(empty($(wpcf-display-date-to))) )"]{!{types field='display-date-to' style='text' format='D d M, Y'}!}{!{/types}!}[/wpv-conditional]
The trouble is that it's not outputting the field data, just the code as is written (i.e. {!{types field='display-date-to.... etc.) in the front end.
I'm using the code in WPBakery in a raw HTML box.
I've removed the conditional code now whilst I'm rectifying the issue but you can see the field as an example on this page - hidden link
You'll see that the To: field label is showing even though the field is empty.
I'm sure this is something simple that I'v missed and I look forward to your thoughts.
Kind regards
James
Hello,
There is a extra ")"in your shortcodes, please try to modify it from:
[wpv-conditional if="( NOT(empty($(wpcf-display-date-to))) )"]{!{types field='display-date-to' style='text' format='D d M, Y'}!}{!{/types}!}[/wpv-conditional]
To:
[wpv-conditional if="( NOT(empty($(wpcf-display-date-to))) "]{!{types field='display-date-to' style='text' format='D d M, Y'}!}{!{/types}!}[/wpv-conditional]
And you can manually debug the wpv-conditional shortcode by adding attribute debug="true", see our document:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#debugging-conditional-output-in-views
Hi Luo,
I tried removing that but it didn't fix the issue. I finally found that the issue was the Raw HTML block wasn't displaying correctly. When I changed to a WP Custom HTML block, it worked as intended!
Many thanks for your help.
Kind regards
James
Thanks for sharing the solution, it will help other users.