Skip Navigation

[Resolved] Conditional HTML with Blocks

This thread is resolved. Here is a description of the problem and solution.

Problem:
We are familiar with the Conditional HTML elaborated here https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

How to use this with Blocks?

Solution:
You can use the Conditional Block.
The logic is the same as for the Conditional HTML and the GUI to control its settings is very familiar to the older ShortCode producing GUI.

You can read more about in the lesson Display Content Conditionally.

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 7 replies, has 2 voices.

Last updated by Beda 4 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#1599913
Conditional.jpg
Conditional2.jpg

Tell us what you are trying to do? I would like to insert a Condition around a Field so that a value displays only if the Post is not Empty. In the attached screenshot, I want to show the Fields and Text only if the taxonomy 'Yith_shop_vendor' is not empty.

I dont know how to do that because the 'yith_shop_vendor' taxonomy is not an option for the Conditional Fields - see screenshot.

Do I have to use a short code? If so, I wrote this but not sure if it's correct:

[wpv-conditional if="('[wpv-post-taxonomy type='yith_shop_vendor' format='name']' ne ' ') By [Organiser as link] [/wpv-conditional]  

Is there any documentation that you are following? Conditional Display

Is there a similar example that we can see?

What is the link to your site? hidden link

#1600441

You can do that (in Blocks) using a Conditional Block.
When you insert that block you get the chance of setting all the conditionals and then inside the block you can insert more blocks that can show your fields, conditionally, based on their "containing" conditional block

However, "If the post is not empty" and "if taxonomy 'Yith_shop_vendor' is not empty" are different things.
One will require custom code https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-custom-functions-in-conditions/#checking-for-empty-post-content, the other is possible to be set directly in the conditional without the need of creating a custom function.

However, in the block you can't check on taxonomies, it seems, you can do that only if using the old IF implementation that you see in Text and Fields Blocks, for example, there you can choose and select the taxonomy succesfully.
This approach is also shown here:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/

I've added the request to allow checking on taxonomies in the new conditional block as well.

#1600443
Bildschirmfoto 2020-04-25 um 16.49.12.png

My apologies, I just saw you can, in fact, check on taxonomies in the Conditional Block as well.

You will have to select "Post Data", then "Current Post" (or post of which you are sure that taxonomy is added), then "Post Taxonomies", then the taxonomy you want to check upon

Does this help?

#1600499

I dont know where are you getting that screenshot from..Where do I go to find it??

I know I can do conditional display of taxonomy but I dont know how to do the code. The examples on the documentations are not relevant to what i'm trying to do and the code I wrote is a guess, at best.

I am WP beginner and not a coder

#1600509
conditional1.jpg

Attached is the screenshot of the functions that I can see, and I dont see the ability to use taxonomies on the conditional block. Organisers (yith_shop_vendor) is not in the list of options that I can select..

In the example provided by the documentation you sent, the condition is set as

[wpv-conditional if="('[wpv-post-taxonomy type='foreign-language' format='slug' ]' ne '' )"] Insert text here [wpv-post-taxonomy type="foreign-language"] [/wpv-conditional]

Is the format for taxonomy always a 'slug'? I wrote 'name' in mine below. However, I cannot write the code inside the Block..

My code: [wpv-conditional if="('[wpv-post-taxonomy type='yith_shop_vendor' format='name']' ne ' ') By [Organiser as link] [wpv-post-taxonomy type='yith_shop_vendor' format'][/wpv-conditional]

#1600521

As mentioned here:
https://toolset.com/forums/topic/conditional-display-inside-block/#post-1600443

There are all the steps on how to find it.
Open the Conditional Block, and follow the steps I outline there.
If you have a taxonomy on the post selected as the source it'll appear in the conditional block.
You can follow the instructions shared earlier here https://toolset.com/forums/topic/conditional-display-inside-block/#post-1600443
>You will have to select "Post Data", then "Current Post" (or post of which you are sure that taxonomy is added), then "Post Taxonomies", then the taxonomy you want to check upon

You are however not using the Conditional Block, as I see now.
You use the Conditional Button as in the Text and Fields - but also there, it will work the same, I tested that as well

If you prefer to use the ShortCode you need to use a ShortCode BLock, I already elaborated that in another ticket, or a Texts and Fields Block.
You can't insert Shortcodes in a native Paragraph block

But you don't need to use ShortCode, you can use the Conditional Block, OR, if you require to hide parts of texts in a Text and Fields block, for example, you can use the IF button

Both GUIs will show the taxonomy, for the Block you will find it in the path outlined here:
https://toolset.com/forums/topic/conditional-display-inside-block/#post-1600443

If this is not working like that on your site, can you let me see the respective backend and front end and allow me to do some editing tests on the site?
I could miss a particular setup or other details that currently don't let me replicate the eventual issue you see

#1601901

My issue is resolved now. Thank you!

#1603769

Great!

Note:
I was able to get it to work using Conditional Block, but I do not know how to do it using Conditional Display, which is what I was doing before.

Conditional Block, Conditional Display, or Conditional HTML, is all the same thing, it's just once in a Block, and once in a GUI (the IF/conditional button in text editors).
While with blocks the editing and results are visual only, with classic editors the result is using ShortCodes (visibly)

On the front end, the result is the same, and the logic of conditions is as well the same

I hope this helps to further master Toolset!