# How do I write conditional logic based on templateType?

**URL:** <https://community.hubspot.com/t/how-do-i-write-conditional-logic-based-on-templatetype/133265>\
**Category:** CMS Development\
**Created:** [May 23, 2025, 11:07am UTC](https://community.hubspot.com/t/how-do-i-write-conditional-logic-based-on-templatetype/133265 "2025-05-23T11:07:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TMisuna](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@TMisuna](https://community.hubspot.com/u/TMisuna)\
**Post date:** [May 23, 2025, 11:07am UTC](https://community.hubspot.com/t/how-do-i-write-conditional-logic-based-on-templatetype/133265/1 "2025-05-23T11:07:43Z")

</div>

I’m trying to work out how to add conditional logic based on templateType in HubSpot CMS. I’ve already looked at the documentation here: [HTML＋HubLテンプレート - HubSpot docs](https://developers.hubspot.jp/docs/guides/cms/content/templates/types/html-hubl-templates)

Inside the global base.html file, I need to inject a structured-data breadcrumb script in the head element, but only for certain template types.

I was wondering if something like the snippet below would work:

```lia-code-sample
{% if templateType == "page" %}
 <script>
 console.log("page");
 </script>
{% elif templateType == "blog_post" %}
 <script>
 console.log("blog_post");
 </script>
{% endif %}

```

I haven’t found any official examples, so I’m unsure whether this approach is valid. In WordPress we can use flexible conditionals for each template; does HubSpot offer anything similar?

Additionally, if the templateType is blog\_post, is there a way to add another layer of conditional logic that targets only a specific blog by its ID?

If anyone knows how to handle these conditionals, I’d appreciate your advice.

---

<div class="post-metadata">

**Author:** ![evaldas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/evaldas/32/69160_2.png) [@evaldas](https://community.hubspot.com/u/evaldas)\
**Post date:** [May 23, 2025, 2:29pm UTC](https://community.hubspot.com/t/how-do-i-write-conditional-logic-based-on-templatetype/133265/2 "2025-05-23T14:29:36Z")

</div>

Hi @TMisuna,

You could utilize the [builtin\_body\_classes](https://developers.hubspot.com/docs/reference/cms/hubl/variables#content-and-contact-variables) variable. HubSpot automatically adds classes to the \<body\> based on the content type.

For example:

- Page would have **.**** hs-site-page**
- Blog listing would have **.**** hs-blog-listing**

So you could use conditional logic based on those.

However, if you need even more granular control, you could try setting a variable in the template itself

`{% set template_var = "page_template_type1" %}`

Regarding the blog IDs, yes you can create rules for that by using the group.id [blog variable](https://developers.hubspot.com/docs/reference/cms/hubl/variables#blog-variables).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![TMisuna](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@TMisuna](https://community.hubspot.com/u/TMisuna)\
**Post date:** [May 24, 2025, 2:50am UTC](https://community.hubspot.com/t/how-do-i-write-conditional-logic-based-on-templatetype/133265/3 "2025-05-24T02:50:10Z")

</div>

`{% if template_meta.path == "theme-name/templates/page.html" %}`

I was able to achieve what I wanted to do by using template\_meta in the form of  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![evaldas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/evaldas/32/69160_2.png) [@evaldas](https://community.hubspot.com/u/evaldas)\
**Post date:** [May 24, 2025, 4:34pm UTC](https://community.hubspot.com/t/how-do-i-write-conditional-logic-based-on-templatetype/133265/4 "2025-05-24T16:34:16Z")

</div>

Glad to hear that worked for you!

One additional tip - if your theme starts having more page templates in the future, instead of adding each individual template to the “if” statement, you could target all site pages with this logic:

`{% if builtin_body_classes is string_containing "hs-site-page" %} `

This would apply to any Website Page, regardless of the template.
