Skip to main content
Problem Solver I
March 18, 2025
Solved

Integrate universal content block dynamically in email template?

  • March 18, 2025
  • 4 replies
  • 270 views

Hi,

I was wondering if there’s a possibility to include a universal content block into an email template without using klaviyos’s built in drag-drop builder.

To explain the situation:
- I have created an universal content block via API ( storing the referencing id and name)
- Now I have a template which for example has a html-block field which should render the content of the universal content → {% render ‘template_id’ %}

Is there any possibility to do this?

Thanks in advance?

    Best answer by jhorngacher

    I found the issue. I gotta have to reverse the logic on how to show the klavio-universal-block. Since dynamic setting of the id is not working, I am just gonna set the universal content as a fixed div and check if the id is in a profile’s reference. Here’s some example code:

    {% if 'universalcontentid' in person.reference %}
    <td data-klaviyo-region="true" data-klaviyo-region-width-pixels="600">
    <div data-klaviyo-universal-block="universalcontentid">
    </div>
    </td>
    {% endif %}



     

    4 replies

    retention
    Partner - Platinum
    2025 Champion
    March 18, 2025

    Hi ​@jhorngacher, welcome to the community!

    If I understand you correctly, you want to get the content of the Universal Block, and inject it into an existing template programmatically.  

    I haven’t done this myself, but I think you can build a “hybrid template” which is a mixture of HTML and editable items, and reference a Universal Block’s ID with this snippet of code in your HTML:

    <td data-klaviyo-region="true" data-klaviyo-region-width-pixels="600">     <div data-klaviyo-universal-block="block_id_1">&nbsp;<div></td>

    Where “block_id_1” is the ID of the universal block that you stored earlier. 

    Here’s some documentation of the “hybrid templates” that might be helpful:

    Now note, this documentation assumes you’re building the HTML template manually as a “HTML Template” by copying/pasting in the HTML code.  You would do this programmatically instead - but I haven’t verified if this works.  Let us know!

    Joseph Hsieh // retentioncommerce.com // X: @retention
    Problem Solver I
    March 19, 2025

    Hi ​@retention , thanks for your answer about my question!

    I have stumbled upon this documentation already and it’s not really helpful at all. If I like integrate this HTML-Code in a HTML-Block it doesn’t do anything. So not loading any Content at all into my mailing template.

    To figure this out, heres what I do exactly:
    → I create the universal content via api

    → I created a template which should include this universal content created. My idea now is to store a dynamic property on a customers profile which includes the references ( ids ) from the universal_content which should be loaded inside the mail template and then send it.

    With the given solution this is not working. Is there anything else or do I just have to like go the non-prefered way of storing HTML-Code inside a customers property?

    Problem Solver I
    March 24, 2025

    Now I finally understood that you can create plain-html templates. Further to this I am now trying to set the dynamic property ( stored as a list ) and load the block with the id, for some reason klaviyo always states that the universal content doesn’t exist. Here’s my example code:
     

    {% for item in person.ppi_reference %}
    <td data-klaviyo-region="true" data-klaviyo-region-width-pixels="600">
    <div data-klaviyo-universal-block="{{ item }}">
    </div>
    </td>
    {% endfor %}

    If I like set the blockId fixed the universalcontent is loaded without any errors, both have the same id!

    jhorngacherAuthorAnswer
    Problem Solver I
    March 25, 2025

    I found the issue. I gotta have to reverse the logic on how to show the klavio-universal-block. Since dynamic setting of the id is not working, I am just gonna set the universal content as a fixed div and check if the id is in a profile’s reference. Here’s some example code:

    {% if 'universalcontentid' in person.reference %}
    <td data-klaviyo-region="true" data-klaviyo-region-width-pixels="600">
    <div data-klaviyo-universal-block="universalcontentid">
    </div>
    </td>
    {% endif %}