May 22, 20208:56 AM - edited May 22, 20208:56 AM
Member
Conditional module
Hi there!
As a front-end React developer, I'm discovering Hubspot and I'm quite amazed about its power. That's said, I have some troubles while trying to include conditionaly a module.
In the UI of the page creation, I want to provide a boolean "Show special feature". So in my HubL template I've written this:
{%
module "hasSpecialFeature"
path="@hubspot/boolean"
label="Show special feature"
export_to_template_context=True
%}
When this special feature is active, I want to provide a new field in the UI, like the color of this special feature. So I've written that:
{% if widget_data.hasSpecialFeature.value %}
Special feature enabled!
{%
module "specialFeatureColor"
path="@hubspot/color"
label="Special feature Color"
export_to_template_context=True
%}
... Other stuff ...
{% endif %}
My goal is to provide the color field in the UI only when the boolean is cheched. That's said, when checked, the text "Special feature enabled!" is well rendered, but the color field does not appear in the UI. I have to reload the page to see it.
Same way when unchecking the boolean : the color field disappear only when I reload the page. It is not a very good UX for the Hubspot creator...
What am I doing wrong? 🙂
Thanks in advance! (I may have other silly questions after this one, please don't mind if I create other subjects ^^')
@adrien-gueret , the answer is going to vary based on where you are developing.
if you are using the design manager at app.hubspot.com, you will look for the display conditions on the right pane of the module
if you are using the local cli (which you should be, you will edit the fields.json file. I recommend building one in the design manager and then fetching it with the cli so you can see how the fields are built
I'm new to Hubspot, so I indeed use the design manager at app.hubspot.com. I probably should have a look on how to use the local CLI.
That's said, if I am not wrong, the solution you suggest concerns conditional fields inside a module. My issue is about conditional modules inside an HubL template.
Maybe it's simply something we are not supposed to do?