CMS Development

cpburke
Contributor

How to hide Hubl module text field if empty

What Hubl expression do I need to add to hide the blog subscription title text if the field is empty? I know it can be done using boolean but haven't been able to get it to work, so the H3 tag still shows up if the title is empty. Thanks in advance.

 

Screen Shot 2019-07-30 at 9.19.23 AM.png

0 Upvotes
4 Replies 4
RJChauhan
Participant

How to hide Hubl module text field if empty

You just need to add like this, h2 tag available only of it has the value
{% if module.title %}
<h2 class="heading m-0">
{{ module.itle }}
</h2>
{% endif %}

0 Upvotes
derekcavaliero
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

How to hide Hubl module text field if empty

@cpburke 

 

@lscanlan 's solution will work, but you can make it more flexible by using the CSS pseudo :empty selector.

 

.hs_cos_wrapper_type_blog_subscribe .form-title:empty{
  display: none;
}

That way you don't accidentally hide it in other scenarios where it may have content.

Derek Cavaliero
Director of Engineering

WebMechanix
www.webmechanix.com
derekcavaliero
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

How to hide Hubl module text field if empty

Whoops - missed his HUBL markup there - his will work perfectly fine as well. Mine is a pure CSS method whereas his is HUBL + CSS

Derek Cavaliero
Director of Engineering

WebMechanix
www.webmechanix.com
lscanlan
HubSpot Alumni
HubSpot Alumni

How to hide Hubl module text field if empty

Hi @cpburke,

 

I don't think it's possible to remove that HTML from the blog subscription module. If you don't include the title parameter, I believe you get the default value, which is "Subscribe Here!". But you could include some CSS to make sure it doesn't display under certain conditions, or some JS to remove it from the page altogether if you need to. So with CSS you could do something like:

 

{% if not module.title %}
  <style>
    .hs_cos_wrapper_type_blog_subscribe .form-title {
      display: none;
    }
  </style>
{% endif %}

Let me know if you have any questions about this.

 

Leland Scanlan

HubSpot Developer Support