CMS Development

peesen
Contributor

Use boolean Tag with "export_to_template_context='true""

SOLVE

Hi, i true to show a module in a custom template when a booean-tag is set true, but the code is not working

 

    {% boolean "partners_active" label='Show Partners', value=False, export_to_template_context=True %}
    {% if partners_active == true %}
      {% include "/my-folder/templates/template-parts/partners.html" %}
    {% endif %}

 

I dont know what i did wrong. Any help? Thank you so much!

0 Upvotes
1 Accepted solution
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Use boolean Tag with "export_to_template_context='true""

SOLVE

@peesen when you use the export_to_template_context you have to call your field with the "widget_data" syntax. Your if statement should be:

 

{% if widget_data.partners_active.value %}
active!
{% endif %}

As long as you're using that in a coded template it should work. If you're trying to use it in a custom module or retrieve a field from a blog post in a blog listing, there is a different syntax. More info here: https://developers.hubspot.com/docs/cms/building-blocks/modules/export-to-template-context

 

Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

1 Reply 1
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Use boolean Tag with "export_to_template_context='true""

SOLVE

@peesen when you use the export_to_template_context you have to call your field with the "widget_data" syntax. Your if statement should be:

 

{% if widget_data.partners_active.value %}
active!
{% endif %}

As long as you're using that in a coded template it should work. If you're trying to use it in a custom module or retrieve a field from a blog post in a blog listing, there is a different syntax. More info here: https://developers.hubspot.com/docs/cms/building-blocks/modules/export-to-template-context

 

Stefen Phelps, Community Champion, Kelp Web Developer