Solved

Can we add If else to dynamic table blocks?

  • 10 January 2023
  • 3 replies
  • 323 views

Badge +8

Hi all,

I have a cart abandonment series and a post purchase series, both of which have a dynamic table block in to show the customers what is in their cart/what they have purchased previously.

Recently a load of sample products have been added to the website in order to allow customers to try 2 free samples with their purchase. We don’t want the samples to show within this dynamic block as the images are not very good, and the data is a little messy. We just want full-sized products that the customer has purchased.

Is there a way I can add an if else statement to a dynamic table block to tell the data to not show when it is a sample? In the event data for placed order, under the item array there is a value product type = sample and I would like to try and target this to remove them. It is showing as {{ event.extra.line_items.1.product.product_type }}

Or can I use show/hide logic? Though I imagine that would hide all the products as opposed to just the samples.

Here are a few screenshots of the standard dynamic table setup I’m using.

If anyone needs anything else, please let me know. Any suggestions would be much appreciated.

icon

Best answer by Dov 12 January 2023, 16:07

View original

3 replies

Userlevel 7
Badge +61

Hi @jadebiscuit,

Thanks for sharing this with us.

You can use conditional statements in dynamic blocks to exclude sample products. This is typically something we recommend you seek the assistance of a developer to assist with. We have a partner directory you can use to seek out assistance.

So say the word “Sample” is in the title of the sample product, an example of what that condition might look like is:


{% if not "Sample" in item.product.title %} Display this content. {% endif %}

Please keep in mind everything contained in this tag it is case sensitive.

I hope that’s helpful.
 

Badge +8

Hi thanks for the reply.

In this instance, I don’t want anything to show in place if the item in the array turns out to be a sample.

So, if I have a customer event setup with 4 items, and items 2 & 3 are samples, I want to show the 1st item, skip the middle two samples and then show the 4th item. (Example below showing - two samples top and single product customer purchased below)

 

Is this possible to leave the if statement blank? Or do you have to specify a value to replace the data with? 

 

The table block is setup as following:

Left column - dynamic image - {{ item.product.images.0.src }}

Right column - text - {{ item.product.title }}, {{ item.quantity|floatformat:0 }}, {{ item.line_price|floatformat:2 }}

With the right column, is it possible to wrap the entire thing in an if statement? Or does it have to be done individually?

Thanks.

Userlevel 7
Badge +61

Hi @jadebiscuit,

Thanks for your reply.

You would need to fill in the “if” statement with a value. I recommend reviewing the community post below that provides a similar solution/example using shipping insurance:

If you’re still having difficulty after reviewing the above, I recommend either contacting one of our partners or reaching out to our support team for further assistance.

Thanks for being a community member.

Reply