Skip Navigation

[Résolu] Conditional Block Based on View >0 Items Found

This support ticket is created Il y a 3 années et 10 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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: Africa/Casablanca (GMT+01:00)

Marqué : 

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Jamal Il y a 3 années et 10 mois.

Assisté par: Jamal.

Auteur
Publications
#1892139

I currently have a content template that displays a view on the right-hand column. I'd like to put a border around this view but only if the view returns any rows. Is it possible to put this logic in the content template itself (i.e. do not put the logic in the view itself, but the block that contains the view)? The reason I'd like to put the conditional styling in the content template instead of the view is so I can use the same view in other areas of the website without putting a border around it. Thanks in advance, and happy New Year.

- Aaron

#1892463

Hello Aaron and thank you for contacting the Toolset support.

I can see two ways to achieve what you are looking for. One way that will be part of the view, using Javascript. And another way will include some custom PHP code and conditional block in the content template.

The first way would be to add some custom Javascript code that will check if the view has any results and apply the border only if the view is used inside that content template. For example, you can add a CSS ID or class to the content template. The Javascript code will check if the view has results and inside that content template, then it will apply the border.

The other way would be to create a custom function or shortcode that will check if the view has results and use it in a conditional block. This custom code can use the get_view_query_results function to check if the view has results.
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results

Then you will need to register the function or the shortcode in Toolset Settings in order to be able to use it inside a conditional block. Check these articles:
- https://toolset.com/course-lesson/using-toolset-conditional-block/#checking-for-shortcodes-values
- https://toolset.com/documentation/programmer-reference/views/using-custom-functions-in-conditions/
- https://toolset.com/documentation/programmer-reference/displaying-custom-functions-with-views-and-using-them-in-conditional-logic/

I hope this helps. Let me know if you have any questions.