CMS Development

kpkreative
参加者

Show module only on specific page with 'if statement'

解決

I have a theme that has been html/hubl  coded.

 

We have a custom module that needs to specifically be placed in the base.html file.

As all templates use base.html as a partial, the custom module placed here, is displaying on all pages, whereas i wish to only have it on the homepage

I could in theory create a clone of base.html for the other pages and remove the module, though i was wondering if there was an if statement available to wrap the module in, to say if it is 'home.html' or 'page-name' display content.

Thanks in advance.
Kev

1件の承認済みベストアンサー
erod
解決策
投稿者

Show module only on specific page with 'if statement'

解決

Hi @kpkreative , 

 

One solution is to use an IF statement to hide it on all pages except the homepage (see below). You may have to change variable. To be honest though, it might just be easier to go with your solution and just clone it. Homepages tend to change the most so having it on its own template might be best. 

 

 

{% if not page.html %}
  <style>
    .module_class {
      display: none;
    }
  </style>
{% endif %}

 

 

元の投稿で解決策を見る

4件の返信
erod
解決策
投稿者

Show module only on specific page with 'if statement'

解決

Hi @kpkreative , 

 

One solution is to use an IF statement to hide it on all pages except the homepage (see below). You may have to change variable. To be honest though, it might just be easier to go with your solution and just clone it. Homepages tend to change the most so having it on its own template might be best. 

 

 

{% if not page.html %}
  <style>
    .module_class {
      display: none;
    }
  </style>
{% endif %}

 

 

kpkreative
参加者

Show module only on specific page with 'if statement'

解決

Thank you so much for this suggestion, i really appreciate it 🙂

0 いいね!
dennisedson
HubSpot製品開発チーム
HubSpot製品開発チーム

Show module only on specific page with 'if statement'

解決

@kpkreative 

I think you are on the right track.  You can find a list of variables you can target for your if statement here

In your module, you could also wrap it in a boolean and have it default to false so you will have it available elsewhere if you want it.

What do you think @erod ?

kpkreative
参加者

Show module only on specific page with 'if statement'

解決

Thanks for this Dennis, i really appreciate your feedback 🙂

0 いいね!