Twig variable in themes to detect builder

My idea is:
A Twig variable available in themes to allow conditional rendering based on whether the theme is rendered through the builder:

{% if isBuilder %}
<!-- code to make the preheader visible -->
{% endif %}

Can be used for conditional code that shows things that should be hidden in emails but visible to users, such as an email preheader.

I think these groups of people would benefit from this idea:
People who send emails

Why I think they would benefit from this idea:
Easier to use features such as preheaders which can be visible in the builder but hidden in email clients

Any code or resources to support this idea:
Provide a “isBuilder” variable when rendering them theme.

Are you willing to work on this idea?:
I can help test

What skills and resources do you need to explore this further?

Hello, you can add content to the template files, would that be any help?
I mean the files that build up the themes themselves.

I think that’s what I mean. I was referring to the email.(twig|mjml]) file.

I was looking for documentation on what Twig variables exist in that scope and ended up reading the source code. From what I could tell, there’s no way to check for the template being rendered in the builder.

There are a few similar requests in the forum:

Personally, I’d love to see a field on the email edit page (before the builder) for a user to define the preheader and that would get added to the email when it’s sent to the relay service.

I haven’t been able to figure out how to use the headers to build an email with annotations to appear in the Gmail promotions tab, but this seems like it would be related to work to make the preheader text easier to edit: Menganotasi email di tab Promosi  |  Gmail  |  Google for Developers

In the Acquia documentation for our email builder, we have code to copy/paste into an HTML block at the beginning of the email:

 <div style="display:none;font-size:1px;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;mso-hide:all;font-family: 'Raleway',sans-serif;">This is preheader text</div>
                                                                                                                                            <!-- Visually Hidden Preheader Text : END -->

This should work in any builder - we didn’t make any changes between the legacy builder and the BEE builder (which is what Acquia uses, rather than GrapesJS)

Is this helpful for what you’re trying to do?

1 Like

Not sure I’m following :slight_smile:
You mean

mj-preview ?

1 Like

Exactly… mj-preview does that.

We added this also to our tz generate Master template (Email templates made easy with twentyZEN GENERATE - My website) so this field is visible in the MJML editor (but only in the mail client preview afterwards).

I guess this is even better than introducing a Mautic function, that needs to inject into a mail template and potentially breaking it.

Just to clarify:

Will your HTML code above hide the preheader in the email but keep it visible in the builder?

I’m using Vanilla Mautic, i.e. GrapesJS.


The HTML I shared will be accessible in the builder, though you won’t actually see it. Here’s a screenshot with our builder - the pink line you see at the top is the HTML content block, but you can’t actually see any content in it because the HTML contains display:none; to hide the content from the actual email.

And here’s what it looks like in my inbox:

Andy, this is only true for the Campaign Studio.
Mautic’s GrapesJS will show it at the top of the editor.

1 Like