Skip Navigation

[Resolved] More help with conditionals

This support ticket is created 5 years, 2 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by matthewC-9 5 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#1367977

Hi - I chatted with Shane yesterday about setting up a conditional that is true when either a view has results or a field has content. I thought I had it working, but today I realized it's only checking for the field content, not the view results.

This is what I've got in the template:

[wpv-conditional if="( $(event-feed) ne '' )" OR ([wpv-view name="page-common-tasks"] ne '')]
<div class="page-sidebar">
[/wpv-conditional]

[wpv-view name="page-common-tasks"]

[types field='event-feed'][/types]

[wpv-conditional if="( $(event-feed) ne '' )" OR ([wpv-view name="page-common-tasks"] ne '')]
</div>
[/wpv-conditional]

The view is set up so that when there are no results, it prints nothing.

On a page with just an event feed, I get the div with the events feed inside it. On a page with common tasks and an event feed, I get both sections with the div wrapping them. But on a page with only common tasks and no event feed, I'm not getting the div, just the view output.

What do I need to do differently to get this working?

#1368181

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthew,

Thank you for getting touch.

Are you referring to the default wrapper div that is around the view ? or have you wrapped your view in some custom div?

Please let me know.

Thanks,
Shane

#1369093

Hey Shane - I'm talking about the custom div in the conditional statement:

[wpv-conditional if="( $(event-feed) ne '' )" OR ([wpv-view name="page-common-tasks"] ne '')]
<div class="page-sidebar">
[/wpv-conditional]

The first part of the conditional works to make it show up, but the second part doesn't.

#1369425

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthew,

Could you add debug='true' to your code so that i can see what is being displayed in the conditional?

Example
[wpv-conditional if="( $(event-feed) ne '' )" OR ([wpv-view name="page-common-tasks"] ne '') debug='true']
<div class="page-sidebar">
[/wpv-conditional]

Thanks,
Shane

#1370091

Yep! Here's what I get on a page with neither element present:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( $(event-feed) ne '' )
    [0] => OR
    [1] => (
    [2] => ne
    [3] => '')
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(event-feed) ne '' )
--------------------
--------------------
Converted expression: ( '' ne '' )
--------------------

And here's what I get on a page with both:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( $(event-feed) ne '' )
    [0] => OR
    [1] => (
    [2] => 
    [3] => class="common-tasks">
    [4] => 
Common
    [5] => tasks

    [6] => 

    [7] => 

    [8] => 
    [9] => href="#">Get
    [10] => a
    [11] => library
    [12] => card
    [13] => 

    [14] => 

    [15] => 
    [16] => href="#">Volunteer
    [17] => at
    [18] => the
    [19] => library
    [20] => 

    [21] => 

    [22] => 
[23] => ne [24] => '') [debug] => true ) #################### Debug information #################### -------------------- Original expression: ( $(event-feed) ne '' ) -------------------- -------------------- Converted expression: ( '
#1370347

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthew,

The conditional looks to be working fine to me.

However I would need to investigate a little further.

Would you mind providing me with admin access to the site as well as a link to the page where you are working on this ?

Thanks,
Shane

#1373213

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthew,

I've made some changes to the syntax of the conditional. Could you check now and let me know if everything is ok ?

Thanks,
Shane

#1373433

The second half of the conditional still isn't working, but I figured out a way to style the page so that it doesn't matter if there's an empty div present (so I'm just including the div tags with no conditional around them). Unless something goes wrong with that down the road, that solves the issue I was trying to solve.