CMS Development

Ali_Knox
Participant | Diamond Partner
Participant | Diamond Partner

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

SOLVE

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

0 Upvotes
1 Accepted solution
Ali_Knox
Solution
Participant | Diamond Partner
Participant | Diamond Partner

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

SOLVE

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.

View solution in original post

0 Upvotes
7 Replies 7
Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

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

SOLVE

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
Anton Bujanowski Signature
0 Upvotes
Ali_Knox
Participant | Diamond Partner
Participant | Diamond Partner

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

SOLVE

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

0 Upvotes
Stephanie-OG
Key Advisor

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

SOLVE

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!

Ali_Knox
Solution
Participant | Diamond Partner
Participant | Diamond Partner

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

SOLVE

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.

0 Upvotes
GiorgioM
Member | Diamond Partner
Member | Diamond Partner

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

SOLVE

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

Schermata 2022-03-08 alle 10.27.35.jpg

 

 

Regards,

Giorgio

0 Upvotes
Ali_Knox
Participant | Diamond Partner
Participant | Diamond Partner

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

SOLVE

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

0 Upvotes
Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

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

SOLVE

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

Anton Bujanowski Signature