# Display template content conditionally

**URL:** <https://community.hubspot.com/t/display-template-content-conditionally/9821>\
**Category:** CMS Development\
**Created:** [August 13, 2018, 12:27pm UTC](https://community.hubspot.com/t/display-template-content-conditionally/9821 "2018-08-13T12:27:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andre9000](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/andre9000/32/53869_2.png) [@andre9000](https://community.hubspot.com/u/andre9000)\
**Post date:** [August 13, 2018, 12:27pm UTC](https://community.hubspot.com/t/display-template-content-conditionally/9821/1 "2018-08-13T12:27:07Z")

</div>

This is probably an easy one, but I can not figure it out how to hide an element if it has no value:

```auto
<h1>{% text "h1" label='Enter H1', value='This is the H1' %}</h1>  

<style>
{% if "h1" is none or "h1" == "" %}
 h1 {
 display: none;
 } 
{% endif %}
</style>

```

This doesn’t work, H1 never gets “display: none;”.

If I try

`{% if h1 is none or h1 == "" %}`

instead (no “” around the name), it will hide H1 even if it has a value.

---

<div class="post-metadata">

**Author:** ![andre9000](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/andre9000/32/53869_2.png) [@andre9000](https://community.hubspot.com/u/andre9000)\
**Post date:** [August 13, 2018, 12:30pm UTC](https://community.hubspot.com/t/display-template-content-conditionally/9821/2 "2018-08-13T12:30:14Z")

</div>

a nicer approach of course would be no wrap the element itself in a condition, so it doesn’t get into the markup if it’s empty. However, this doesn’t seem to work, because then it is not possible to set a value for h1 anymore.

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 13, 2018, 1:44pm UTC](https://community.hubspot.com/t/display-template-content-conditionally/9821/3 "2018-08-13T13:44:58Z")

</div>

@Hello @andre9000 - Your HUBL tags are going to be in a dictionary, so you would inspect the data cominng from your tag by accessing “widget\_data”. You should combine this with the “export\_to\_template\_context” tag attribute as well.

Shorthand:

```auto
{% text "h1" label="Enter H1" value="This is the H1" export_to_template_context="true" %}
{{'<h1>'+widget_data.h1.value+'</h1>' if widget_data.h1.value != ""}}

```

Or, longhand:

```auto
{% text "h1" label="Enter H1" value="This is the H1" export_to_template_context="true" %}
{% if widget_data.h1.value != '' %}
 <h1>{{widget_data.h1.value}}</h1>
{% endif %}

```

* * *

If this answer helped, please, mark as solved 😄

* * *

[tim@belch.io](mailto:tim@belch.io) | [forms.belch.io](https://forms.belch.io) | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me [on slack](http://slack.belch.io/).

---

<div class="post-metadata">

**Author:** ![andre9000](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/andre9000/32/53869_2.png) [@andre9000](https://community.hubspot.com/u/andre9000)\
**Post date:** [August 14, 2018, 8:54am UTC](https://community.hubspot.com/t/display-template-content-conditionally/9821/4 "2018-08-14T08:54:53Z")

</div>

Awesome, works perfectly. Thank you, good to know!
