New to HubL - Can't seem to get the Content from Content.name

SOLVE
Occasional Contributor | Gold Partner

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 %}

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Occasional Contributor | Gold Partner

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.

Reply
0 Upvotes
6 Replies 6
Advisor

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







check Did my post help answer your query? Help the Community by marking it as a solution
Reply
0 Upvotes
Occasional Contributor | Gold Partner

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

Reply
0 Upvotes
Highlighted
Advisor

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








check Did my post help answer your query? Help the Community by marking it as a solution
Occasional Contributor | Gold Partner

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

Reply
0 Upvotes
Regular Advisor

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 }}

 


Stephanie O'Gay GarciaHubSpot Design / Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

Occasional Contributor | Gold Partner

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.

Reply
0 Upvotes