# Twig variable in themes to detect builder

**URL:** <https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166>\
**Category:** Ideas and Feature Requests\
**Created:** [March 6, 2024, 8:54am UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166 "2024-03-06T08:54:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakobpersson](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jakobpersson](https://forum.mautic.org/u/jakobpersson)\
**Post date:** [March 6, 2024, 8:54am UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/1 "2024-03-06T08:54:59Z")

</div>

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

```auto
{% 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?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [March 6, 2024, 9:25am UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/2 "2024-03-06T09:25:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jakobpersson](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jakobpersson](https://forum.mautic.org/u/jakobpersson)\
**Post date:** [March 6, 2024, 9:58am UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/3 "2024-03-06T09:58:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![a.towne](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/a.towne/32/1351_2.png) [@a.towne](https://forum.mautic.org/u/a.towne)\
**Post date:** [March 6, 2024, 9:24pm UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/4 "2024-03-06T21:24:54Z")

</div>

There are a few similar requests in the forum:

> [@E-Mail PreHeader](https://forum.mautic.org/t/e-mail-preheader/13245):
>
> Hi Mauticians. I was wondering if anyone has had any success in inserting a pre-header into a Blank Template email. I know how to do this if I build the html myself, however finding it challenging to do manually. Regards, Mike

> [@Email Preview / Preheader Text](https://forum.mautic.org/t/email-preview-preheader-text/7717):
>
> I noticed today that our client’s email preview text in Appl Mail consisted of the unsubscribe content, which we have placed at the beginning of the email, clearly not helping with open rates and needs optimised. It would be great to add an extra field into the interface for such content to be added automatically from the main body or added manually. With exception to manually creating a hidden content area, is there an easier way to achieve this? Cheers Derek

> [@Email Preheaders?](https://forum.mautic.org/t/email-preheaders/9213):
>
> I’m not seeing how to implement/modify email preheaders. Can anyone point me in the right direction? Google search didn’t provide an answer. Thanks!

> [@Allowing to define the email preheader text](https://forum.mautic.org/t/allowing-to-define-the-email-preheader-text/10604):
>
> There was already a well defined github issue, which didn’t make it into this list: [https://github.com/mautic/mautic/issues/2800](https://github.com/mautic/mautic/issues/2800) This is an important way to improve email opening rates. With an additional field users could easily define the preheader. However, it needs to be injected into the mail at the right place.

> [@Edit email header](https://forum.mautic.org/t/edit-email-header/7253):
>
> Hi, I am new on Mautic and I take the opportunity to congrats all of the contributors of this great project … I have a question : I would like to personalise the header of the email I send with mautic. The reason is I want to use some tricks to help my email not consider as spam, especially with microsoft email server ([outlook.com](http://outlook.com), [hotmail.com](http://hotmail.com)). Is there a way with the GUI to do that ? Is it possible to do that with a modification of a php file ? If yes, could you give me some he…

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 &nbsp;|&nbsp; Gmail &nbsp;|&nbsp; Google for Developers](https://developers.google.com/gmail/promotab/overview)

In the [Acquia documentation](https://docs.acquia.com/campaign-studio/channels/emails/email-builder#html-block) for our email builder, we have code to copy/paste into an HTML block at the beginning of the email:

```auto
 <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?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [March 6, 2024, 10:14pm UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/5 "2024-03-06T22:14:50Z")

</div>

Not sure I’m following 🙂  
You mean

mj-preview ?

---

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [March 7, 2024, 8:42am UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/6 "2024-03-07T08:42:41Z")

</div>

Exactly… mj-preview does that.

We added this also to our tz generate Master template ([Email templates made easy with twentyZEN GENERATE - My website](https://twentyzen.com/en/lp/twentyzen-generate/)) 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.

---

<div class="post-metadata">

**Author:** ![jakobpersson](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jakobpersson](https://forum.mautic.org/u/jakobpersson)\
**Post date:** [March 7, 2024, 4:21pm UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/7 "2024-03-07T16:21:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jakobpersson](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jakobpersson](https://forum.mautic.org/u/jakobpersson)\
**Post date:** [March 7, 2024, 4:22pm UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/8 "2024-03-07T16:22:42Z")

</div>

This?

[https://documentation.mjml.io/#mj-preview](https://documentation.mjml.io/#mj-preview)

---

<div class="post-metadata">

**Author:** ![a.towne](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/a.towne/32/1351_2.png) [@a.towne](https://forum.mautic.org/u/a.towne)\
**Post date:** [March 7, 2024, 4:50pm UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/9 "2024-03-07T16:50:15Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/1/14b60985b497055c2f8cf98319c7472ee45758eb.jpeg)

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

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/d/d0f1bca66bb80adf14b3276ba85c30ec1175cabc.png)

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [March 9, 2024, 8:29am UTC](https://forum.mautic.org/t/twig-variable-in-themes-to-detect-builder/31166/10 "2024-03-09T08:29:17Z")

</div>

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