CMS Development

SD_dev
Member

How to add custom code based on if page is homepage

SOLVE

Hello, 

 

I'm trying to add a CSS class to my header IF the page is the homepage, else I want nothing additonal to happen.

 

I believe I need to add an IF statement to my header code, but I cannot find any example like this in the documentation: https://developers.hubspot.com/docs/cms/hubl/if-statements

 

Could someone tell me how I can achieve this or point me in the right direction?

 

Thank you

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

How to add custom code based on if page is homepage

SOLVE

Hey @SD_dev 

 

You could check the length of the url path with request.path.

Documentation here

 

 

class="{{request.path|length > 1 ? '' : 'is-homepage-class'}}"

 

 

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

View solution in original post

5 Replies 5
bestbushcraft
Member

How to add custom code based on if page is homepage

SOLVE

Hi Kevin, that worked brilliantly. Can't believe I missed that when looking through the list.

Thank you for your help.

Regards

Bestbushcraft

 

Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

How to add custom code based on if page is homepage

SOLVE

 @SD_dev 

 

Looks like @Anton found a much better solution!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
SD_dev
Member

How to add custom code based on if page is homepage

SOLVE

Hi Kevin, that worked brilliantly. Can't believe I missed that when looking through the list.

Thank you for your help 😄

Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

How to add custom code based on if page is homepage

SOLVE

Hey @SD_dev 

 

You could check the length of the url path with request.path.

Documentation here

 

 

class="{{request.path|length > 1 ? '' : 'is-homepage-class'}}"

 

 

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

How to add custom code based on if page is homepage

SOLVE

Hey @SD_dev 

 

You could check the length url path with request.path. Documentation here

class="{{request.path|length > 1 ? '' : 'is-homepage-class'}}"

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev