HubSpot Content Hub HubL Cheat Sheet: 50+ Snippets You’ll Actually Use

HubSpot Content Hub HubL Cheat Sheet: 50+ Snippets You’ll Actually Use

  • Home
  • Blog
  • HubSpot Content Hub HubL Cheat Sheet: 50+ Snippets You’ll Actually Use

If you’re working with HubSpot Content Hubyou’ll eventually run into HubL (HubSpot Markup Language) — the engine behind dynamic templates, modules, and content rendering.

Instead of searching documentation every time, this HubL cheat sheet gives you practical, ready-to-use snippetsthat you can plug directly into your templates and modules.

What Is HubL (Quick Recap)

HubL is HubSpot’s templating language used inside:

  • Page templates
  • Blog templates
  • Custom modules
  • Dynamic pages (HubDB)

It allows you to:

  • Insert dynamic content
  • Use conditions and logic
  • Loop through data
  • Access CRM and HubSpot objects

🔥 1. BASIC VARIABLES

Display Page Name

{{ content.name }}

Display Page Title

{{ page_meta.html_title }}

Display Current URL

{{ request.path }}

🔁 2. CONDITIONAL LOGIC

Simple If Condition
{% if contact.firstname %}
Hello {{ contact.firstname }}
{% endif %}

If / Else
{% if contact.firstname %}
Hi {{ contact.firstname }}
{% else %}
Hi there!
{% endif %}

Multiple Conditions
{% if contact.lifecycle_stage == "customer" %} Welcome back!
{% elif contact.lifecycle_stage == "lead" %} Check out our demo
{% endif %}

🔄 3. LOOPS

Loop Through Blog Posts

{% for post in blog_recent_posts %}
<h2>{{ post.name }}</h2>
{% endfor %}

Loop with Limit

{% for post in blog_recent_posts limit=3 %}
<p>{{ post.name }}</p>
{% endfor %}

📊 4. HUBDB (VERY IMPORTANT)

Get Table Rows
{% set rows = hubdb_table_rows(123456) %}

Loop Through HubDB Rows
{% for row in rows %}
<h3>{{ row.name }}</h3>
{% endfor %}

Filter HubDB Rows
{% set rows = hubdb_table_rows(123456, "city=Delhi") %}

🔗 5. LINKS & URLS

Internal Page Link
<a href="{{ content.absolute_url }}">View Page</a>

File Link
<a href="{{ file_by_id(123).url }}">Download</a>

🧱 6. MODULE FIELDS

Access Text Field

{{ module.heading }}

 

Image Field

<img src="{{ module.image.src }}" alt="{{ module.image.alt }}">

 

Link Field

<a href="{{ module.link.url }}">{{ module.link.text }}</a>

🎯 7. PERSONALIZATION

First Name Token
{{ contact.firstname }}

Fallback Value
{{ contact.firstname|default("there") }}

🧠 8. STRING & TEXT FILTERS

Uppercase
{{ "hello"|upper }}

Lowercase
{{ "HELLO"|lower }}

Truncate Text
{{ post.summary|truncate(100) }}

📅 9. DATE FORMATTING

{{ post.publish_date|datetimeformat('%b %d, %Y') }}

🔍 10. REQUEST DATA

Get Query Parameter

{{ request.query_dict.search }}

 

Detect Device (basic)

{{ request.user_agent }}

🧩 11. PARTIALS & INCLUDES

Include Another File
{% include "custom/header.html" %}

🎨 12. CONDITIONAL CSS CLASS

<div class="{% if module.dark_mode %}dark{% else %}light{% endif %}">

🔁 13. REPEATERS (MODULE LISTS)

{% for item in module.features %}
<h3>{{ item.title }}</h3>
{% endfor %}

🧠 14. GLOBAL VARIABLES

{{ site_settings.company_name }}

📦 15. SAFE OUTPUT

{{ module.rich_text|safe }}

⚡ 16. CHECK IF VALUE EXISTS

{% if module.image %}
<img src="{{ module.image.src }}">
{% endif %}

🧪 17. DEBUGGING

Print Variable
{{ variable|pprint }}

🎯 18. PAGINATION (BLOG)

{% if blog_page_has_next_page %}
<a href="{{ blog_next_page_url }}">Next</a>
{% endif %}

🧱 19. DYNAMIC BODY CLASS

<body class="{{ content.slug }}">

🧠 20. CLEAN URL SLUG

{{ content.slug }}

🚀 PRO TIPS (IMPORTANT)

  • Always use fallbacks for personalization
  • Avoid heavy logic inside templates (performance)
  • Use HubDB for scalability
  • Keep modules reusable, not hardcoded

📌 Key Takeaway

HubL is the backbone of dynamic websites in HubSpot Content Hub. By mastering a small set of powerful snippets, you can build scalable, flexible, and highly customized websites without reinventing the wheel every time.

Leave a reply

Related Post

How Do HubSpot Content Hub SEO Recommendations and Optimization Tools Work?
September 3, 2026
SEO Strategy, Content Optimization, SEO Recommendations

How Do HubSpot Content Hub SEO Recommendations and Optimization Tools Work?

Search engine optimization (SEO) is an important part of making sure website content can be discovered by potential visitors. HubSpot Content Hub includes built-in SEO tools hat help users optimize pages and blog posts for search engines.

Read More
How Do HubSpot Content Hub Custom Modules Work?
July 3, 2026
Split Testing, Conversion Optimization, Page Testing

How Do HubSpot Content Hub Custom Modules Work?

Custom modules are one of the most powerful features available in HubSpot Content Hub. They allow developers to create reusable content components that editors can easily add to pages using the drag-and-drop editor.

Read More
How Does HubSpot Content Hub Security and Website Protection Work?
August 8, 2026
Email Marketing, Lead Nurturing, Campaign Integration

How Does HubSpot Content Hub Security and Website Protection Work?

Website security is an essential part of managing any online platform. Businesses need to ensure that their websites are protected from threats such as data breaches, malicious attacks, and unauthorized access. HubSpot Content Hub includes several...

Read More

Have a Project in Mind?

Let’s talk about what you need and how we can make it happen.

Request a quote