Skip Navigation

[Closed] Nesting Content Template Inside Conditional Statement Inside a View

This support ticket is created 2 years, 5 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)

This topic contains 7 replies, has 4 voices.

Last updated by Shane 2 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#2201059

I have a content template for single products. Inside that content template I have a view for displaying related products. Inside that view, I setup two conditional blocks within the view output:

1) product category contains "books"
2) NOT product category contains "books"

Depending on which condition is true, it is set to display one of two content templates. However, it only ever shows the content template from condition 2 above, even if condition 1 is true. I have set the conditional block to debug mode and it says the condition is evaluated as being true, yet it is still displaying the wrong content template.

Any assistance you can provide in troubleshooting would be appreciated. Thanks.

- Aaron

#2201065
word-book-does-not-appear.PNG
content-template.PNG

As a follow-up, I also tried putting this same conditional statement inside of another content template just to decomplicate things. It still doesn't work. In the attached screenshots, you can see the conditional statement and just a paragraph with the word "books" if the condition is true. However, the actual output shows the debug info saying it's true but the word "books" does NOT appear in the output.

- Aaron

#2201587

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2021-10-21 at 12.58.39.png

I've tried something similar on my own test site and it is working (screenshot, using WC dummy data).

I think to see why it's not working on your site we'll need access to it, if that's okay.

I will mark your next reply as private so that we can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site.

Can you also confirm the url of where we can see the problem.

#2201709

Hi Nigel - It's not coming up with private-reply options.

#2201745

Minesh
Supporter

Languages: English (English )

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

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2201971
no-content-displayed.PNG
content-template-2.PNG

To add to what's already been said, I tried modifying content template 25451 to conditionally show product components such as an "Add to Cart" button if the post being displayed is post_type = 'product'. The debugging shows the condition is evaluated true, yet none of the contents in the conditional block are displayed. Could this all have something to do with WooCommerce? Attached are a couple more screenshots for you.

#2202001

Sorry for so many messages - I'll take a break after this one! I was able to get the conditional content to come up properly when adding a slash to the front of the post type so it only shows content if the post_type = '/product' - I'm not sure why the slash is necessary. However, none of the WooCommerce blocks show up. I've figured out that they will only come up if they are added directly in the archive. If they are contain in a nester content template, then they don't show up. Can you confirm this is by design? If so, I will take this out of the nested content template and just put it directly into the archive template itself. I was just trying to avoid needing to update content in multiple places, but I can live with it if need be.

I have not yet gone back and tested this on the original "books" issue, but I'm assuming it follows similar logic and that I'll need to put the formatting directly into the archive output as opposed to embedding a content template. I'll stand by until I hear more. Thanks again.

- Aaron

#2203147

Shane
Supporter

Languages: English (English )

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

Hi Aaron,

I had a look at the Book issue.

The problem is that you're checking against the parent category i.e Books. Our conditional isn't checking against the parent category but rather the category/term that is actually selected on the post.

Given that this post below has the term "Peak Oil Essential Books" selected. It won't validate the conditional that is checking for Books even though Peak Oil Essential Books is a child of books. To workaround this you will need to select Both Parent and Child categories if you're going to evaluate the post against the parent.
hidden link

. However, none of the WooCommerce blocks show up. I've figured out that they will only come up if they are added directly in the archive. If they are contain in a nester content template, then they don't show up. Can you confirm this is by design?

I'm not sure what you're referring to by non-woocommerce blocks. Taking a look at the product page only the items you have in your content template are showing up. I need some clarification here.

Thanks,
Shane

The topic ‘[Closed] Nesting Content Template Inside Conditional Statement Inside a View’ is closed to new replies.