<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I write conditional logic based on templateType? in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156583#M43119</link>
    <description>&lt;P&gt;Glad&amp;nbsp;to hear that worked for you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% if builtin_body_classes is string_containing "hs-site-page" %} &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would apply to any Website Page, regardless of the template.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 24 May 2025 16:34:16 GMT</pubDate>
    <dc:creator>evaldas</dc:creator>
    <dc:date>2025-05-24T16:34:16Z</dc:date>
    <item>
      <title>How do I write conditional logic based on templateType?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156204#M43112</link>
      <description>&lt;P&gt;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: &lt;A class="" href="https://developers.hubspot.jp/docs/guides/cms/content/templates/types/html-hubl-templates" target="_new" rel="noopener"&gt;https://developers.hubspot.jp/docs/guides/cms/content/templates/types/html-hubl-templates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;I was wondering if something like the snippet below would work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% if templateType == "page" %}
  &amp;lt;script&amp;gt;
    console.log("page");
  &amp;lt;/script&amp;gt;
{% elif templateType == "blog_post" %}
  &amp;lt;script&amp;gt;
    console.log("blog_post");
  &amp;lt;/script&amp;gt;
{% endif %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone knows how to handle these conditionals, I’d appreciate your advice.&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 11:07:43 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156204#M43112</guid>
      <dc:creator>TMisuna</dc:creator>
      <dc:date>2025-05-23T11:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write conditional logic based on templateType?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156305#M43113</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/749449"&gt;@TMisuna&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could utilize the&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/reference/cms/hubl/variables#content-and-contact-variables" target="_blank" rel="noopener"&gt;builtin_body_classes&lt;/A&gt; variable. HubSpot automatically adds classes to the &amp;lt;body&amp;gt; based on the content type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Page would have &lt;STRONG&gt;.&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;hs-site-page&lt;/STRONG&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;Blog listing would have &lt;STRONG&gt;.&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;hs-blog-listing&lt;/STRONG&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could use conditional logic based on those.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you need even more granular control, you could try setting a variable in the template itself&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% set template_var = "page_template_type1" %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the blog IDs, yes you can create rules for that by using the&amp;nbsp;group.id &lt;A href="https://developers.hubspot.com/docs/reference/cms/hubl/variables#blog-variables" target="_blank" rel="noopener"&gt;blog variable&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 23 May 2025 14:29:36 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156305#M43113</guid>
      <dc:creator>evaldas</dc:creator>
      <dc:date>2025-05-23T14:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write conditional logic based on templateType?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156510#M43118</link>
      <description>&lt;LI-CODE lang="markup"&gt;{% if template_meta.path == "theme-name/templates/page.html" %}&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;I was able to achieve what I wanted to do by using template_meta in the form of&lt;BR /&gt;Thank you very much.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 May 2025 02:50:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156510#M43118</guid>
      <dc:creator>TMisuna</dc:creator>
      <dc:date>2025-05-24T02:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write conditional logic based on templateType?</title>
      <link>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156583#M43119</link>
      <description>&lt;P&gt;Glad&amp;nbsp;to hear that worked for you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% if builtin_body_classes is string_containing "hs-site-page" %} &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would apply to any Website Page, regardless of the template.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 May 2025 16:34:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/How-do-I-write-conditional-logic-based-on-templateType/m-p/1156583#M43119</guid>
      <dc:creator>evaldas</dc:creator>
      <dc:date>2025-05-24T16:34:16Z</dc:date>
    </item>
  </channel>
</rss>

