Mautic Community Forums

Help with twig syntax

Hi, I’d like to use the twig engine in our custom emails. Specifically, where a slot has no content that slot and its corresponding area (

, , , etc.) should not display as an empty space. Empty template areas are unattractive and I’d like to place a conditional on a ALL my slots for layout attractiveness and flexibility.



I’m sure this is incorrect. Can somebody please assist with the proper syntax to do this please?
Code:
{% if slots:content is not empty %}
<?php $view['slots']->output('content'); ?>
{% endif %}

Hi, I’d like to use the twig engine in our custom emails. Specifically, where a slot has no content that slot and its corresponding area (

, , , etc.) should not display as an empty space. Empty template areas are unattractive and I’d like to place a conditional on a ALL my slots for layout attractiveness and flexibility.

I’m sure this is incorrect. Can somebody please assist with the proper syntax to do this please?

{% if slots:content is not empty %} <table><tr><td> <?php $view['slots']->output('content'); ?> </table></tr></td> {% endif %}

No sorry I didn’t but that page link is very helpful. I’m beginning to understand it better. Thank you.

Question, what are the ‘page_title’, ‘top1_title’ elements? Is this an array referencing other slot titles? If so, can I do this:

[code]{% if slotHasContent([‘top1’]) %}

{{ slot('top1') }}
{% endif %}[/code]

If not what do they actually reference?

Forgive me in advance for being a script-kitty and not a full programmer.

Thanks. I’ll give it a try.

No I’m sorry to say this code doesn’t work. It displays as text in the delivered email. I’m running Mautic 1.3.1. Is there something else I should have included/activated for this code to process? It looks like it’s not processing.

{% if slotHasContent(['sub-title']) %} <!--slogan--> <tr> <td align="center" style="font-family: 'Open Sans', Arial, sans-serif; color:#898989; font-size:12px;line-height: 28px; font-style:italic;"><?php $view['slots']->output('sub-title'); ?></td> </tr> <!--end slogan--> {% endif %}