If rich text field has value then


Is there a category for development questions(code questions)? Leaving this uncategorized as there isn't a clear option.

Simple question, Hubl documentation on if statements doesn't seem to cover in regards to what may be an issue with the new design manager.

Custom module. Within that module a Rich text field. Need a simple if statement, if the field has value then do something. Again the documentation doesn't align with the experience of the custom module builder in regards to including fields within it. I've tried a handful of options based on that documentation with no success.

Field name is "heading". How do i simply say IF rich text has value THEN do this thing.

Tried these:

{% if widget_data.heading.value %}
{% endif %}

{% if widget_data.heading.src %}
{% endif %}

{% if module.heading.value %}
{% endif %}

None worked


Hi @jau, all HubL related questions should go into the COS/Content category. I've moved it over to that category for you.

As for your question, for a rich text module, you should be able to have the following which would accomplish what you're looking for:

{% if module.heading %}
{% endif %} 

The conditional statements themselves haven't changed in the new DM, but the reference of widget_data / widget / module depends on which context you're in. widget vs module should be exactly the same, but widget_data is usually used if you're exporting any values to the template context. If you share exactly what you're looking to do, I may be able to advise further. Just send over a link to the page you're on and a description of your goal and I'll do my best!



That works! If you don't mind me asking where did you find that documented? I'm referencing this page:

I don't see any information on if statements in regards to fields within a module. That page covers a handful of other scenarios. Now that you explain it, it makes sense to me, if within module there is heading makes sense. Where i'm getting lost is trying to find the correct documentation to use this language properly(So i can not bother you guys on here! And keep my projects moving forward).

My use of src and value above was more out of desperation than logic. Having tried to utilize the information available and not succeeding.

Thanks again for your help I really appreciate it.


Hi @jau, I don't think there's documentation on the distinction between using .src or .value or leaving the if statement without further qualifying the object you're referencing. We are definitely looking to expand upon our documentation and make things a bit more explicit when it comes to HubL functions, delimiters and syntax. HubL, though, is based loosely off Jinja2. If you check out their documentation, this can clarify a bit more as to how if statements can work: http://jinja.pocoo.org/docs/2.10/templates/#if

The way I think about it is, if I want to check to see if a certain aspect of a field in a custom module exists, I'll use .src or .value. For example, if I don't just want to check if an image is present, but actually want to check if the alt attribute on that image is present, I'll write something like this:

{% if module.image.alt %}
   <p>{{ module.image.alt }}</p>
{% endif %}

If I just want to check if the image field itself exists/has data, I wouldn't qualify it further with .alt:

{% if module.image %}
   <p>{{ module.image.alt }}</p>
{% endif %}

The second example might not be a great choice though, just in case the image actually doesn't have any alt text associated with it.

One thing that you can really use to your advantage is the Developer Info if you are confused about which object/property on an object you should be using: https://designers.hubspot.com/docs/hubl/how-to-use-developer-info-on-cos-pages.

If I'm unsure of what I should be referencing, I'll check the developer info for the object and the particular property on that object that i'd want to print out or do something to, which helps immensely when seeing if I should be referencing something one way or another.



Thanks so much for all the info! I'll have a lot of reading to do this weekend, I had read briefly about jinja being the base for a lot of this at one point, hadn't thought about using developer tools though.

Seriously thank you!


@jau no problem! Glad I could help :slight_smile: have a great weekend.