Solved

Using Klaviyo variables and logic from web feed?

  • 5 October 2021
  • 9 replies
  • 938 views

Badge +2
  • Contributor IV
  • 7 replies

Apologies if this has been asked, I tried looking before posting this.

Can we ship Klaviyo code inside of a web feed and would it be parsed the same way once it’s received?

For example, if I populate web feed content with a Klaviyo/Django {% if %} argument and logic, would it be parsed after the web feed response is received?

Let’s say we ship a feed.footer component as compiled HTML that has Klaviyo logic for a conditional {% if %} and it wants to access person.id — would this work as expected?

icon

Best answer by Walid 6 November 2021, 01:17

View original

9 replies

Badge +2

Hey @Dov & @walid.bendris ,

 

This is awesome. Those are definitely some Django (or Klaviyo?) tags and filters I wasn’t aware of - aside from safe, which I thought was a Liquid thing. Thank you so much for this info. Let me loop back and we’re going to do a small test refactor and apply some of this and I’ll let you know how this all goes. This seems pretty bang-on though.

 

Thanks again. I’ll be in touch soon.

Badge +3

Hi @pete !

Dov caught me up on the thread here behind the scenes. You can in fact render both HTML and Django from a feed in our editor by using various filters and tags, here's how:

HTML from a feed
You can render HTML from a feed by using the Django filter |safe, this tells our interpretor that the content is "safe" to render as raw HTML rather than just displaying it as the original text. You can also use this strategy for raw HTML strings contained in event data or profile properties. Here's how this would look:

{{ feeds.html_and_django_test.html_property|safe }}

Django and HTML from a feed
You'll notice that the same strategy doesn't work for Django in a feed (or event or profile property). This is due to the discrete steps in our rendering pipeline. In order to display feed content, we need to "render Django" on the template. Then, we would need to "render Django" again on the template in order to render the feed content as Django. We don't do this by default or allow it to be re-triggered in order to avoid render loops, but luckily there is a tag that takes care of this for us.

The "render_variable_assign" tag can be used to set a variable on the template and the "render_variable" tag will render that variable on the page. This tag will be evaluated by our render pipeline before the initial Django render takes place, so you can set up a variable in the first render cycle using that tag so the content will be rendered during the following cycle. Here's how you would do this:

{% render_variable_assign feeds.html_and_django_test.html_and_django as feed_django_data %}
{% render_variable feed_django_data %}

Given a template like the following:

 

Assuming each property name is what it says it is (html_property is a property containing html, etc), previewing this template would look like this:


I've added an example feed and a template (called "[kl] data from feed example") to your account so you can see how this works!

Badge +2

Hi @Dov - just checking in here.

Badge +2

Hey @Dov thanks for the help, and congrats on the new launch of the template editor.

 

We’re working around this instead as it seems the universal saved blocks may be out later this year. For now, there is some basic questions here.

  • You mentioned we can use Klaviyo personalization variables inside of Web Feed responses. That doesn’t seem to be the case, or I may be missing something - can you let us know simply if we can use Klaviyo variables inside of web feed components? See my attachment below.
  • If we can’t use the above, is it possible to do a string replace from a web feed response? It doesn’t seem to be supported in the Django language by design -- or if you guys have a universally registered filter that we may be missing, this would be very helpful. For example, replacing { “sample_key”: “https://somewhere.to/some/place?={{ EMAIL }}” } and replacing that {{ EMAIL }} with bruce@springsteen.com (or whatever we wanted).
  • If neither are possible - please let me know and we’ll find a workaround.

 

Our JSON
Output

 

Please let me know. Thanks again.

Userlevel 7
Badge +61

Hi @pete,

As it stands today, updating templates and template blocks is a manual process (see more on this topic here),however, I have some wonderful news to share.

By end of Q4, we will be pushing out a brand new template editor including a feature that will allow you to add a saved block to multiple messages at once, then later edit the saved block(s) and see those edits reflected across all messages.

Help is on the way, thanks for your patience here!

Dov

Badge +2

Hi @pete,

Thanks for the update.

I apologize I was mistaken originally, there actually is not a way to get web feed content interpreted as HTML in the email source, as it will come in as a string. The immediate workaround is to provide a feed that uses strings and apply the styling within the Klaviyo editor. Sorry about that initial confusion.

 

Ah. Bummer. No worries about the misunderstanding.

 

So the problem we’re facing is here:

  • We have a ton of flows. Like, plans for scaling it up to 100+.
  • Each of these flows are composed of many different templates, messages, etc. Let’s say they can be anywhere from 1 - 10, or even more, messages each depending on the flow logic.
  • This is going to get exponentially harder to maintain with design and template updates. Say we update a navigation block or a footer block, or a content block. We’d have to manually go through all of these flows and update ALL templates. That sucks, big time. (Pun intended)
  • What we’re trying to avoid here is rolling our own system - which we are capable of - but we don’t want to essentially rebuild Klaviyo.
  • There must be a way to update all of these templates at once? Or maybe there isn’t. Which would suck - because we dig Klaviyo.

 

To note:

  • I have read this article but it seems to be what you said for above - strings.
  • I have read about the Campaigns API.
  • I have read about the Templates API.
    • This puts us at the same problem - if we dynamically update and redeploy all templates - we still need to manually update them in the flows to be in sync.

 

I’d love to hear your thoughts, @Dov . What do you think a good solution is here?

Userlevel 7
Badge +61

Hi @pete,

Thanks for the update.

I apologize for the initial confusion, there actually is not a way to get web feed content interpreted as HTML in the email source, as it will come in as a string. The immediate workaround is to provide a feed that uses strings and apply the styling within the Klaviyo editor. Sorry about that initial confusion.

 

Badge +2

Hey @Dov , I tried this out and it doesn’t seem to be compiling the variables nor the HTML. Any input is appreciated. The JSON response was received successfully, but it’s being parsed as a string.

 

Editor

 

Klaviyo Preview
In email

 

Userlevel 7
Badge +61

Hi @pete,

No problem at all! Thank you for your question.

Yes, you can use if statements in our web feeds and it would parse in the same manner once received. For more information on web feeds, I recommend checking out our article on the topic here.

Thanks for being a member of our community.

Reply