Help displaying module fields within if statement in email template

I have a custom module with a handful of fields that I want to use to conditionally include an HTML block in an email template.

The first field in the module is a boolean → display_client_manager_message

If that is set to true in the email editor, we present the editor with three fields to edit a custom message:

  1. client_manager_message → rich_text
  2. client_manager_name → text
  3. client_manager_title → text

The if condition works nicely and I can get the code block within the statement to conditionally display. But I can’t get the value of the module fields to display within the block no matter what I’ve tried from examples in docs, or pasting the snippet from the module editor in the Design Manager…

Please help a HubL noob! :face_with_tongue:

{% module "module_160446479058547" path="/Coded files/Custom/email/default/Client Manager Message", overrideable=True, label="Client Manager Message", export_to_template_context=True %}

{% if widget_data.module_160446479058547.display_client_manager_message == true %}
 <p>Showing our conditional block</p>
 <p>
 {{ module.client_manager_message }}
 </p>
 <p>{{ module.client_manager_name }}<br>
 {{ module.client_manager_title }}</p>
{% endif %}

Hey @farser , with the way you have this written (using widget_data) I’m under the impression you aren’t writing the code block within the custom module itself? If not then the reason your content isn’t showing is because you aren’t using the widget_data format on them.

{% module "module_160446479058547" path="/Coded files/Custom/email/default/Client Manager Message", overrideable=True, label="Client Manager Message", export_to_template_context=True %}

{% if widget_data.module_160446479058547.display_client_manager_message == true %}
 <p>Showing our conditional block</p>
 <p>
 {{ widget_data.module_160446479058547.client_manager_message }}
 </p>
 <p>{{ widget_data.module_160446479058547.client_manager_name }}<br>
 {{ widget_data.module_160446479058547.client_manager_title }}</p>
{% endif %}

I would just put the code in the custom module itself though instead of using export_to_template_context. It would be a lot cleaner that way. So in the HTML section of your custom module you would put :

{% if module.display_client_manager_message == true %}
 <p>Showing our conditional block</p>
 <p>
 {{ module.client_manager_message }}
 </p>
 <p>{{ module.client_manager_name }}<br>
 {{ module.client_manager_title }}</p>
{% endif %}

And then put the module snippet in your template wherever you’re wanting the message to show.

{% module "module_160446479058547" path="/Coded files/Custom/email/default/Client Manager Message", label="Client Manager Message" %}

Works! Thank you so much. I was missing this simple concept. Cheers