Expand my Community achievements bar.

Applications for the Community Advisor Program Class of 2025 are NOW OPEN – Apply Today!

E-mail Template Fragments Customization - Retaining Inline Variable Value after Breaking Inheritance

Avatar

Level 1

Let's say I have a code like this as part of my visual fragment made to be configurable by user via inline variable fragment_design:

 

{{#inline "fragment_design" name="design type"}}fragment-regular{{/inline}}
{% let fragment_color = "" %}
{%#if contains(fragment_design,"fragment-regular")%}
    {% let fragment_color = "#000000" %}
{%else%}
    {% let fragment_color = "#666666" %}
{%/if%}
<div class="{{{fragment_design}}}" style="color:{{{fragment_color}}};"></div>

 

I'm using contains instead of equals here because of a problem with line breaks around variableThis code works mostly fine inside an e-mail template visual editor. I still get these strange line breaks but fragment_design variable's value is actually there and correct fragment_color variable is also being displayed in the output code:

 

<div class="
fragment-regular
" style="color:#000000;"></div>

 

Problems start when I break inheritance of a fragment. While trying to simulate content I get an error: "invalid syntax Missing schema field: fragment_design". It seems that after breaking inheritance fragment_design variable is no longer available (and even not declared) which is somewhat understandable and makes a lot of sense. It's simply being changed wherever it's being used to a hard coded string, in this case fragment-regular. I went around mentioned error by adding let variable declaration on the very top of my original code:

 

{% let fragment_design = "" %}

 

This way simulating content starts to work without any further errors and I can actually preview my e-mail template. The new output code is this:

 

<div class="fragment-regular" style="color:#666666;"></div>

 

As you can see the class is correct but the color is not. That's because after breaking inheritance if/else statement reads fragment_design variable as an empty string. And here's my question: is there any way to assign the value of an inline variable editable by user to a regular variable that won't vanish after breaking fragment's inheritance? I already tried all kinds of things and syntaxes here. Most promising idea was using some "buffer" variable like this:

 

{% let fragment_design_value = "{{fragment_design}}" %}

 

Fragment with this code saves without problems but unfortunately in this case I get some kind of an error already on e-mail template editing screen. Instead of an actual variable declaration I see something like this, even before breaking fragment's inheritance:

 

{% let fragment_design_value = "EXCS_CODE_BLOCK_2_}" %}

 

Possibility of retaining inline variable's value is crucial in the scenario where these fragments are to be preconfigured with inline variables first and have its contents edited later, after breaking fragment's inheritance. I hope there's some solution to this problem. Any help will be much appreciated.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies