Hi! I'm working on a site using classic Views. In one of my content templates, I'd like to create a conditional to check whether either of 2 different views has results for the page in question, then display output based on the results. (The views already exist and work in the context of the page - I'm trying to add some wrapping markup only if they have results.) What's the best way to do this?
Thanks!
Sarah
Hi Sarah,
Thank you for contacting us and I'd be happy to assist.
To suggest the most efficient way to achieve this, I'll need to see how these views are being placed on the page and where the conditional wrapper needs to be.
Can you please share temporary admin login details, along with the link to the page where these can be seen?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
regards,
Waqar
Thank you for sharing these details.
Looking into the content template, I understand that you'd like to show the div with class "page-sidebar", only when some content exists inside it.
(that content can be from either of the two views or the field "event-feed")
The most efficient way I can think of would be to include some custom script in the content template's "JS editor" which can look for a presence of a div element inside the div with class "page-sidebar", and if none exists, hide it.
( screenshot: hidden link )
jQuery(document).ready(function(){
if( jQuery('.entry-content div.page-sidebar div').length == 0 ) {
jQuery('.entry-content div.page-sidebar').hide();
}
});
Well, huh. 🙂 I hadn't thought of doing it that way, but that certainly is simpler. I'm generally trying to make sure everything still works without JavaScript, but - since this is mostly just to control the page layout, it seems perfectly reasonable to treat it as an enhancement - someone without JS won't get any different content, just a slightly different layout. That seems perfectly fine to me.
My issue is resolved now. Thank you!