Skip Navigation

[Resolved] Using HTML inside a conditional

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

Problem:
How to check HTML code with conditional output shortcode [wpv-conditional]

Solution:
To compare HTML with [wpv-conditional] shortcode, You can follow the proposed solution with the following reply:
=> https://toolset.com/forums/topic/using-html-inside-a-conditional/#post-576070

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Alex W 7 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#575903
Screen Shot 2017-10-04 at 01.15.23.png

I am trying to use the following conditional:

[wpv-conditional if="( $(wpcf-book-reviews) ne '' ) AND ( $(wpcf-book-reviews) ne '<li></li>' )"  debug="true"]

The list items HTML in it are stopping it from working I think, plus messed up the debug (see screenshot)

So I changed it to this:

[wpv-conditional if="( $(wpcf-book-reviews) ne '' ) AND ( $(wpcf-book-reviews) ne '<li></li>' )"  debug="true"]

and now the debug looks like this, but the conditional is still not working:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( $(wpcf-book-reviews) ne '' ) AND ( $(wpcf-book-reviews) ne '<li></li>' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-book-reviews) ne '' ) AND ( $(wpcf-book-reviews) ne '<li></li>' )
--------------------
--------------------
Converted expression: ( '
' ne '' ) AND ( '
' ne '<li></li>' )
--------------------

How can I have the list HTML inside the conditional please?

#575974

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I do not know why you want to check html tags with [wpv-conditional] shortcode but yes I checked the issue locally and I can see the same output as you did. It looks like there is some issue or its expected but I will report this to our Devs to get concrete answer on that and ask why it decodes the html entities within [wpv-conditional] shortcode.

However - when I tried following statement:

[wpv-conditional if="( $(wpcf-book-reviews) ne '' ) AND ( $(wpcf-book-reviews) ne '<li></li>' )"  debug="true"]

I can see [wpv-conditional] shortcode outputs correct content as field is not empty and field value is not equal to '

  • .

    If you can tell me your exact requirement with problem URL, I will try to share workaround.

    #575998

    Hi Minesh

    I won't go into the reasons why I need to check html tags in the conditional but the fact is that I do.

    When I use the same conditional you did it breaks as per my previous screenshot. When I try to use HTML entities in place of the opening tag the debug suggests that it should work, but it's still returning true even when wpcf-book-reviews contains the list tags.

    Here is a book that has

    <li></li>

    in the wpcf-book-review field. You can see the debug output:
    hidden link

    #576010

    Minesh
    Supporter

    Languages: English (English )

    Timezone: Asia/Kolkata (GMT+05:30)

    Could you please share temporary access details so that I can check if I can provide you some workaround.

    #576070

    Minesh
    Supporter

    Languages: English (English )

    Timezone: Asia/Kolkata (GMT+05:30)

    Could you please check now. I've changed your [wpv-conditional] statement as given under:

    [wpv-conditional if="( $(wpcf-book-reviews) ne '' ) AND ( '[types field='book-reviews' output='raw'][/types]' ne '<li></li>' )"]
        <div class="reviews">
          <h3>Reviews</h3>
          <ul>
          [types field='book-reviews'][/types]
          </ul>
        </div>
        [/wpv-conditional]
    

    Now, I can see its working properly as per your requirement. Could you please confirm.

    #576102

    Thank you that's working perfectly now. I'll remember to use this method in the future too.