Skip to main content
Solved

Data feed Django filter not show empty lines when loop through all

  • April 15, 2022
  • 1 reply
  • 186 views

Forum|alt.badge.img+4

Hi,

 

So I am creating an email with a custom data feed. Everything works fine, I use a filter on the feed to display information only when the filter matches true. But I want it to do 2 things:

  • When it doesn’t match to true, don’t do anything (so also no line breaks)
  • When the first match is found, stop the loop

Can anyone help me on this? I am using this formula at the moment:

{% if item.bid_price == "800.00" %}

{{ item.bid_price }}

{% endif %}

 

Just for some extra background, maybe there is a better way to achieve what we want:

We have a custom datafeed. Within this feed, we need to filter on 2 levels; the brand and the style. E.g. someone buys a chair with style X, we want to filter the feed and present a couch with style X

Good to know, we use a custom integration and have the following available:

  • custom data feeds
  • product catalog

Hope anyone can help me with this because I am stuck.

Best answer by Dov

Hi @RobinDijst,

Thanks for sharing this question with us.

On your first question, the if statements should be typed as if they are all on a single line. You can use this online tool to remove the line breaks. Also, ensure to edit the block's Source when editing the if/else code.

On your second question, you can use the "slice" filter. To use this filter, adjust the Repeat For value by adding the filter to the end. Here’s an example: 

feeds.KlaviyoBlog.articles|slice:':3'
 

In this example, |slice:':3' will cause only the first three entries that meet your criteria to display. 

I hope that’s helpful.

View original
Did this topic or the replies in the thread help you find an answer to your question?

1 reply

Dov
Forum|alt.badge.img+61
  • Klaviyo Alum
  • 1493 replies
  • Answer
  • April 15, 2022

Hi @RobinDijst,

Thanks for sharing this question with us.

On your first question, the if statements should be typed as if they are all on a single line. You can use this online tool to remove the line breaks. Also, ensure to edit the block's Source when editing the if/else code.

On your second question, you can use the "slice" filter. To use this filter, adjust the Repeat For value by adding the filter to the end. Here’s an example: 

feeds.KlaviyoBlog.articles|slice:':3'
 

In this example, |slice:':3' will cause only the first three entries that meet your criteria to display. 

I hope that’s helpful.