Hey @RAnderson91,
thanks for the code.
Okay - so “hidden modules” might be a wrong term here, as most people (including me) would thing of this doc first hand.
The export_to_template_context function is most commonly used for modifying the template, but technically you could use it to hide/show modules & sections.
I think there are two things to look at.
- The export_to_template_context function will prevent the module from rendering on the actual page as it’s provides the module data to the template without rendering the actual module.
- the form module doesn’t have a form_id, so the module is not getting rendered
This means:
{% module "form_module"
path="@hubspot/form"
label="Form",
export_to_template_context=true,
form={
"form_id":"12345-65486-6484621-456812"
}
%}
{{ widget_data.form_module|pprint }}
will show in the template:
(SizeLimitingPyMap: {definition_id=null, export_to_template_context=true, extra_classes=widget-type-form, field_types={follow_up_type_automation=boolean, sfdc_campaign=salesforcecampaign, form=form, notifications_are_overridden=boolean, notifications_override_email_addresses=email, form_follow_ups_workflow_id=workflow, simple_email_for_live_id=followupemail, title=text, follow_up_type_simple=boolean}, follow_up_type_automation=false, follow_up_type_simple=false, form={form_id=12345-65486-6484621-456812, response_type=redirect, message=Thanks for submitting the form., redirect_id=null, redirect_url=http://www.google.com}, form_follow_ups_workflow_id=, label=Form, module_id=1155238, notifications_are_overridden=false, notifications_override_email_addresses=, parent_widget_container=null, path=@hubspot/form, sfdc_campaign=, simple_email_for_live_id=, smart_objects=[], smart_type=NOT_SMART, title=, type=module, wrap_field_tag=div})
If you want to display the form somewhere in the template, the code would look like this:
{% module 'custom_module'
path="path/to/custom/module"
content="
form={
"form_id"= widget_data.form_module.form.form_id
}
"%}
Personally I think this will get out of hand and hard to manage quite fast as you could use the actual form module directly or implement a form function in a custom module.
If you like to stick to export_to_template_context and toggle the visibility of a module I’d recommend to do it like this:
{% module "show_form" path="@hubspot/choice", label="Display form on page", value="true, false" export_to_template_context=True %}
...
{% if widget_data.show_form.value == "true"
{% module "form_module"
path="@hubspot/form"
label="Form",
form={
"form_id":"12345-65486-6484621-456812"
}
%}
{% endif %}
In a custom module it’s quite similar and a bit better in terms of UX imo.
You can either add a boolean, choice-field or simply nothing 
The custom module code would look like this:
{% if module.show_form %} {# boolean version #}
{% form
form_to_use="{{ module.form_field.form_id }}"
response_response_type="{{ module.form_field.response_type }}"
response_message="{{ module.form_field.message }}"
response_redirect_id="{{ module.form_field.redirect_id }}"
response_redirect_url="{{module.form_field.redirect_url}}"
gotowebinar_webinar_key="{{ module.form_field.gotowebinar_webinar_key }}"
%}
{% endif %}
{% if module.show_form == "true" %} {# choice field version #}
{% form
form_to_use="{{ module.form_field.form_id }}"
response_response_type="{{ module.form_field.response_type }}"
response_message="{{ module.form_field.message }}"
response_redirect_id="{{ module.form_field.redirect_id }}"
response_redirect_url="{{module.form_field.redirect_url}}"
gotowebinar_webinar_key="{{ module.form_field.gotowebinar_webinar_key }}"
%}
{% endif %}
{% if module.form_field.form_id %} {# will render the form as soon as a form_id is present #}
{% form
form_to_use="{{ module.form_field.form_id }}"
response_response_type="{{ module.form_field.response_type }}"
response_message="{{ module.form_field.message }}"
response_redirect_id="{{ module.form_field.redirect_id }}"
response_redirect_url="{{module.form_field.redirect_url}}"
gotowebinar_webinar_key="{{ module.form_field.gotowebinar_webinar_key }}"
%}
{% endif %}
best,
Anton