Hide widget container if its empty

tstrack
Contributor | Platinum Partner

I'd like to hide a widget container if there isn't any modules inside of it. My code currently looks like this:

 

<!-- Comps -->
<h3>Comps</h3>
{% widget_container "comps_container" %}
{% end_widget_container %}
<hr class="simple">

What can I wrap this in to hide everything if there aren't any modules inside of the container?

 

Thanks!

0 Upvotes
3 Replies 3
relabidin
HubSpot Alumni

Hi @tstrack,

 

You'll want to use an Expression test to evaluate whether or not your widget container is empty. The link I provided has a great example of how to perform an if/then test in HubL. However, I lack the experience to provide the exact code on how to do this for your specific need. Hopefully that documentation is helpful!

 

Rami 

creativetech
Participant

@tstrack

Were you able to figure this out? I want to achieve similar functionality. I'm looking to hide a panel/section/group if a module within the panel/section/group value is set to true (boolean). I thought something like the following would work, but it doesn't.

 

{% if widget_data.hide_module.value == "true" %}

<!-- hide section -->

{% else %}

<!-- show section --> {{ html }}

{% endif %}

0 Upvotes
tstrack
Contributor | Platinum Partner

@creativetech

 

{% boolean "hide_section" label='Hide Section', value=True, export_to_template_context=True %}

 

{% if not widget_data.hide_section.body.value %}

<!-- Your code here -->

{% endif %}

 

Just make sure to change the names in bold.