Oct 18, 2018 8:23 AM
Hi,
I'm new to Hubl and can't seem to get the content from content.name for an if statement. I've tried numerous ways to no avail. Below is as example of what I'm trying to do.
Any help would be apprecaited.
<h1>{{ content.name }}</h1>
{% if content.name == 'Blog' %}
<h2 class="sub_heading">Latest blog insights from Node4.</h2>
{% elif content.name == 'Events' %}
<h2 class="sub_heading">Latest Event insights from Node4.</h2>
{% elif content.name == 'News' %}
<h2 class="sub_heading">Latest News from Node4.</h2>
{% endif %}
Solved! Go to Solution.
Oct 18, 2018 12:18 PM
Thanks Stephanie, Anton.
Strangley if I use page_meta.name instead of content.name the "if" statement works. But they both output the same when using {{ x }}.
Thanks for the efficency as well Stephanie, the customer has written a long paragraph to use as the html text.
Cheers.
Oct 18, 2018 8:48 AM
Hi @Ali_Knox,
as far as I understand your code, you want to change the "dynamicly". For my knowing this can be only achieved by using javascript
For Hubl you'll need some widgets. You can add them on the right sidebar while "programming" a module.
Your code will work if you add a "choice field".
But you'll have to change the naming/wording.
There is no
{{content.name}}
function availible.
You can add a (Rich-)text widget to your module and name it "Name". Then the code would be
{{module.name}}
Then you add the choice field, name it "choice" and set up your 3 options.
Your code snippet would be
{% if module.choice == 'Blog' %} <h2 class="sub_heading">Latest blog insights from Node4.</h2> {% elif module.choice == 'Events' %} <h2 class="sub_heading">Latest Event insights from Node4.</h2> {% elif module.choice == 'News' %} <h2 class="sub_heading">Latest News from Node4.</h2> {% endif %}
regards,
Anton
![]() | Did my post help answer your query? Help the Community by marking it as a solution |
Oct 18, 2018 10:57 AM
Anton,
Thank you for you help. I'm probably not being clear nor using the correct terminology. At the moment theres a module that I have inheritted. On the listing templates in Hubspot, they using the same background cover as a global module with {{ content.name }} included over the background image. This content.name is outputting Blog, Event or News as a Title dependant which area you go into. These are brough through from the settings > Blog section and uses the field Header.
What I wanted to do was as the page is shown, have some subtext underneath that is dependant on the content.name.
Am I way off the pace.
Thanks,
Ali
Oct 18, 2018 12:03 PM - edited Oct 18, 2018 12:06 PM
Hi Ali and Anton,
Maybe try this logic:
<h1>{{ content.name }}</h1> {% if 'Blog' in content.name %} <h2 class="sub_heading">Latest blog insights from Node4.</h2> {% elif 'Events' in content.name %} <h2 class="sub_heading">Latest Event insights from Node4.</h2> {% elif 'News'' in content.name %} <h2 class="sub_heading">Latest News from Node4.</h2> {% endif %}
I'm not 100% sure why yor original condition doesn't work, but this seemed to work in my tests.
EDIT: the below should also be more efficient if the title is the word you're looking for.
<h1>{{ content.name }}</h1> <h2 class="sub_heading">Latest {{ content.name }} insights from Node4.</h2>
You can use the lower filter to change it to lower case if needed:
{{ content.name|lower }}
If this helped, please mark it as the solution to your question, thanks!
Oct 18, 2018 12:18 PM
Thanks Stephanie, Anton.
Strangley if I use page_meta.name instead of content.name the "if" statement works. But they both output the same when using {{ x }}.
Thanks for the efficency as well Stephanie, the customer has written a long paragraph to use as the html text.
Cheers.
Mar 8, 2022 4:42 AM
Hi @Ali_Knox
visually the output looks the same but by default {{content.name}} output is wrapped with a span element.
<span id="hs_cos_wrapper_name" class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_text" style="" data-s-cos-general-type="meta_field" data-hs-cos-type="text">CONTENT NAME VALUE</span>
{{page_meta.name}} instead is not wrapped.
https://developers.hubspot.com/docs/cms/hubl/variables
Regards,
Giorgio
Oct 18, 2018 9:03 AM
Anton,
Thank you for you help. I'm probably not being clear nor using the correct terminology. At the moment theres a module that I have inheritted. On the listing templates in Hubspot, they using the same background cover as a global module with {{ content.name }} included over the background image. This content.name is outputting Blog, Event or News as a Title dependant which area you go into. These are brough through from the settings > Blog section and uses the field Header.
What I wanted to do was as the page is shown, have some subtext underneath that is dependant on the content.name.
Am I way off the pace.
Thanks,
Ali
Oct 18, 2018 11:47 AM - edited Oct 18, 2018 11:48 AM
Hi @Ali_Knox,
do you want to change it automaticly or is it a possibility to change it by hand?
By hand would be much easier and faster way.
This would be the method I've mentioned above.
Also I've got an idea how to manage the the "automatic" way. But I need some time to test it.
Maybe @tjoyce, @Stephanie-OG or @Jsum have an idea how to acomplish this in a better/faster way.
regards,
Anton