CMS Development

tstrack
投稿者 | Platinum Partner
投稿者 | Platinum Partner

Hide widget container if its empty

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 いいね!
3件の返信
creativetech
参加者

Hide widget container if its empty

@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 いいね!
tstrack
投稿者 | Platinum Partner
投稿者 | Platinum Partner

Hide widget container if its empty

@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.

relabidin
元HubSpot社員
元HubSpot社員

Hide widget container if its empty

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