HubL Reference

Table of contents
Close

HubL module syntax & parameters

Modules are editable areas of HubSpot pages or emails. While you can add modules to a template layout using the drag and drop Template Builder, you can also create modules using HubL. HubL modules can be defined in a coded template file, a HubL template module, or a blog content module. Below is a comprehensive list of modules and their parameters.

Basic module syntax

Module tags are made up of the following components:

  • A unique name for that module - gives the module a unique identity in the context of the template
  • Path (depends on tag) - defines the location of where the module is in the design manager. The path for HubSpot default modules should always start with @hubspot/ followed by the type of module. See the example below and the HubL Supported Tags page for more. 
  • Parameters (optional) - specify additional module information

{% module "unique_module_name" path="@hubspot/module_type" parameterString='String parameter value', parameterBoolean=True %}

{# Sample of a default HubSpot text module #}
{% module "job_title" path="@hubspot/text", label="Job Title", value="Chief Morale Officer" %}

{# Sample of a custom module #}
{% module "faqs" path="/Marketplace/HubSpotSiteSetup/Vast_Site_Setup/Custom_Modules/Vast FAQ Module", label="Vast FAQ Module" %}

HubL module tags are delimited by "{%", and require the type of module and a unique name to specified. The unique name must be in quotes following the type of module. Module names must use underscores instead of spaces or dashes.

The unique name is used to match content inputted with the page/email editor with the corresponding HubL module tag. For example, if you code a HubL module tag with the same name in two different areas of a template, users will only have one module to edit in the editor, but changes to that module will apply in both locations. 

In addition to the two required components of a module tag, HubL modules support various parameters that specify a module's behavior as well as how it renders. Parameters are key-value pairs separated by commas. Parameters have different types including string, boolean, integer, enumeration, and JSON list. String parameters should have their value in quotes*, while Boolean parameters do not require quotes around their True or False values. Below is an example of a basic text module with a label and a value parameter specified.

*String parameter values can be written in either single or double-quotes. In this example, the unique module name has double quotes and the parameter values are in single quotes. This syntax is helpful when parameter values include HTML markup with multiple attributes. Boolean parameter values are capitalized for legibility.

{% module "simple_section_title" path="@hubspot/text" label='Enter text for this section title', value='This is a section title' %}

<span id="hs_cos_wrapper_simple_section_title" class="highlight hs_cos_wrapper hs_cos_wrapper_widget hs_cos_wrapper_type_text"

style="" data-hs-cos-general-type="widget" data-hs-cos-type="text">

This is a section title

</span>

Block syntax

While most modules have parameters that control default content, there may be situations where you need to add large code blocks to the default content of a module. For example, you may want to include a large block of HTML as the default content for a rich text or HTML module. Rather than trying to write that code into a value parameter, you can use HubL block syntax.


{% module_block module "my_rich_text_module" path="/My Rich Text Field Module", label="My Rich Text Field Module"  %}
    {% module_attribute "rich_text_field_variable" %}
        <div>My HTML block</div>
    {% end_module_attribute %}
{% end_module_block %}

Prior to the module_block syntax, widget_block was used. It follows the same pattern but the opening tags were widget_block, and widget_attribute. Closing tags were end_widget_attribute, end_widget_block.

The widget_block syntax is deprecated but you don't need to update old code.

The parameter that immediately follows module_block or widget_block(deprecated) is the type_of_module parameter.

In nearly all of our documentation you will find we use module. V2 HubSpot Modules are normal modules, like what you can create. Therefore there's no longer a need to use a different type_of_module.

While widget_block is deprecated, and you should use module_block. You may inherit old code using widget_block and type_of_module.

The type_of_module supports V1 HubSpot module names for example: rich_text or raw_html. Additional parameters can be added to the first line of HubL. The second line defines which parameter the contents of the block will be applied to. For example, for a rich_text module this should be the html parameter. For a raw_html module, this would be the value parameter (see both examples below). 

{# widget_block is deprecated, use module_block instead. This example is only to
explain what type_of_module was used for, for those with legacy code. #}
{% widget_block rich_text "my_rich_text_module" overrideable=True, label='My rich-text module'  %}
        {% widget_attribute "html" %}
            <h2>New Module</h2>
            <p>Add content here.</p>
        {% end_widget_attribute %}
{% end_widget_block %}
<span id="hs_cos_wrapper_my_rich_text_module" class="hs_cos_wrapper hs_cos_wrapper_widget hs_cos_wrapper_type_rich_text" style="" data-hs-cos-general-type="widget" data-hs-cos-type="rich_text">
    <h2>New Module</h2>
    <p>Add content here.</p>
</span>

content_attribute

In addition to regular and block syntax, there are certain instances where you may want to specify a large block default content for a predefined content variable. The most common example of this proves to be the content.email_body variable. This variable prints a standard email body that can be altered in the content editor. Since this isn't a standard HubL module, we use a content_attribute tag to specify a block of default content. The example below shows the email body variable being populated with a default content code block.


{% content_attribute "email_body" %}
        <p>Hi {{ contact.firstname }},</p>
        <p>Describe what you have to offer the customer. Why should they read? What did you promise them in the subject line? Tell them something cool. Make them laugh. Make them cry. Well, maybe don't do that...</p>
        <p>Use a list to:</p>
        <ul>
            <li>Explain the value of your offer</li>
            <li>Remind the reader what they’ll get out of taking action</li>
            <li>Show off your skill with bullet points</li>
            <li>Make your content easy to scan</li>
        </ul>
        <p><a href="http://hubspot.com">LINK TO A LANDING PAGE ON YOUR SITE</a> (This is the really important part.)</p>
        <p>Now wrap it all up with a pithy little reminder of how much you love them.</p>
        <p>Aw. You silver-tongued devil, you.</p>
        <p>Sincerely,</p>
        <p>Your name</p>
{% end_content_attribute %}  

Passing dicts to module parameters

For modules with fields that expect dicts, you can pass them like you would other parameters. If it's cleaner to you or you plan to re-use the values, you can set the dict to a variable, and pass the variable to the parameter instead.

{% module_block module "social_buttons",
  path="@hubspot/social_sharing", 
  email={
    "default": true,
    "enabled": false,
    "img_src": "https://..."
  }
%}
{% end_module_block %}

Parameters available for all modules

Certain modules have certain special parameters, but there are also parameters supported by all modules. Below is a list of parameters supported by all modules.

Parameters name Type Description Default value
 label  string  Defines the internal title of the module in the content editor. This parameter can also be used to give users additional instructions.  None 
 overrideable  boolean Controls whether or not the module can be edited in the content editor. This parameter is the equivalent of using the lock module feature in the Template Builder UI.  True
 no_wrapper  boolean Setting no_wrapper=True removes the wrapping markup from around the content of a module. Module output to the page is always wrapped in a with special classes. This wrapping markup makes it so when you click the module in the preview pane, the editor scrolls to that module. There may be instances where you want to remove the wrapper, such as if you want to use a text module to populate the destination of an anchor tag href attribute.  False
 extra_classes  string Adding an extra classes parameter will add those classes to the wrapping of the module content. You can add multiple classes at once, by separating the classes with spaces (ie extra_classes='full-width panel').   None
 export_to_template_context  boolean If True, instead of rendering the HTML, the parameters from this widget will be available in the template context. To retrieve a parameter with HubL, you will widget_data tag. To learn more about how to use this parameter and the widget_data tag, check out this article.  False
 unique_in_loop  boolean This parameter can be used, when a module is defined within a loop, to append the unique module name with the loop.index. If True, this makes it possible to print a different version of that module with each iteration of the loop. You can see an application of this parameter, here.  False

To see a complete list of all module types and their parameters, click here.

Field based parameters

You can set the value of custom module fields using parameters.

{% module "faq" path="faq", label="Accessible FAQ Module" faq_group_title="Commonly Asked Questions" %}

faq_group_title in this case is not one of the parameters that is available for all modules. faq_group_title is specific to this custom module. It is the variable name for a field in the module.

Some fields are simple and the parameter simply expects a string, integer, true/false. Others may expect an object. Providing the values in the correct format is down to you as there is no in-editor value validation based on settings you set in the custom module's field settings. Example: A module has a number field that has a minimum value set to 1, you pass into the parameter a 0. There is no warning to indicate your value is invalid.

 

How module field type's translate to parameters
Field's name Type Example keys
Blog blog id 1234567890  
Boolean true/false false  
Choice value string "option_1"  
Color object
{
  "color" : "#ffffff",
  "opacity" : 100
}
color
6 character hexidecimal format
opacity
integer 0 - 100
CTA String, CTA id
"fb9c0055-6beb-489d-8dda-3e1222458750"
 
Date timestamp
1566360000000
 
Datetime timestamp
1566360000000
 
Email address array of email address strings
["develop@hubspot.com", "design@hubspot.com"]
 
File URL string to file
"https://cdn2.hubspot.net/hubfs/file.pdf"
 
Follow Up Email Follow up email id
1234567890
 
Font Object with font keys and values
{
  "size" : 12,
  "size_unit" : "px",
  "color" : "#000",
  "styles" :{
    "text-decoration" : "underline"
  },
  "font" : "Alegreya",
  "fallback" : "serif",
  "variant" : "regular",
  "font_set" : "GOOGLE"
}
size
font size without unit type
size_unit
font size unit string
  • "px"
  • "pt"
  • "em"
  • "rem"
  • "%"
  • "ex"
  • "ch"
color
hex color code string
styles
supported properties
"font-weight"
"normal" / "bold"
"font-style"
"normal" / "italic"
"font-style"
"none" / "underline"
Form Object with form keys and values
{
  "form_id" : "9aa2e5f3-a46d-4774-897e-0bc37478521c",
  "response_type" : "redirect",
  "redirect_url" : "http://www.hubspot.com",
  "redirect_id" : null,
  "form_type" : "HUBSPOT"
}
form_id
The form's ID. How to get a form's id.
response_type
"redirect" / "inline"
message
Message displayed if using response_type "inline". String supporting html.
redirect_url
String, absolute URL to a webpage
redirect_id
Page/Post id to redirect to
form_type
"HUBSPOT" / "TICKET_FORM"
HubDB Table hubDB table id 123456789  
Icon object with icon keys and values
{ 
  "name" : "align-center",
  "unicode" : "f037",
  "type" : "SOLID"
}
name
The icon's name
unicode
The unicode symbol for the font the icon is from
type
Symbol style. "SOLID" / "REGULAR"
It is recommended you set an icon field and view the values that way, to set the parameters properly.
Image object with image keys and values
{
  "src" : "https://cdn2.hubspot.net/hubfs/image.jpeg",
  "alt" : "an_image",
  "width" : 100,
  "height" : 100
}
src
Image URL
alt
Image alt text, used by screen readers and search engines
width
The width at which the image is to be displayed
height
The height at which the image is to be displayed
Meeting String of meeting link url "https://app.hubspot.com/meetings/developers-r-kewl"  
Menu Menu ID 123456789  
Number integer 1  
Page Page ID 1234567890  
richtext string, can contain html "<h1>Hello, world!</h1>"  
Salesforce Campaign string, salesforce campaign id "7016A0000005S0tQAE"  
Simple Menu array of menu item objects
[ 
  { 
    "isPublished" : true,
    "pageLinkId" : 123456789,
    "pageLinkName" : "My page",
    "isDeleted" : false,
    "categoryId" : 1,
    "subCategory" : "site_page",
    "contentType" : "site_page",
    "state" : "PUBLISHED_OR_SCHEDULED",
    "linkLabel" : "This is a page",
    "linkUrl" : null,
    "linkParams" : null,
    "linkTarget" : null,
    "type" : "PAGE_LINK",
    "children" : [ ]
  } 
]
isPublished
true/false is the menu item's page published?
pageLinkId
Page id in the CMS
pageLinkName
The page's actual name in the CMS
isDeleted
true/false
categoryId
  • 1 - Site Page
  • 3 - Blog post
subCategory
  • site_page
  • landing_page
  • blog
  • normal_blog_post
contentType
  • site_page
  • landing_page
  • blog
state
  • DRAFT
  • DRAFT_AB
  • PUBLISHED
  • PUBLISHED_OR_SCHEDULED
  • PUBLISHED_AB
  • SCHEDULED
linkLabel
text the user reads and clicks
linkUrl
actual URL the user is sent to upon clicking
linkParams
# links or ? query parameters
linkTarget
if open in new tab is enabled "_blank" otherwise "null"
type
  • "PAGE_LINK"
  • "PAGE_LINK_WITH_PARAMS"
  • "NO_LINK"
children
array of menu item objects, identical to individual menu items.
Tag Tag ID/slug (ID is recommended) 1234567890  
Text string "it's like any other string"  
URL object with URL keys and values
{ 
  "type" : "CONTENT",
  "href" : null,
  "content_id" : 123456789
}
type
  • "EXTERNAL" for non HubSpot non-email URLs
  • "CONTENT" for pages, blog posts, and landing pages
  • "FILE" for files uploaded to the file manager
  • "EMAIL_ADDRESS" for email addresses
  • "BLOG" for blog listing pages
href
String, the URL you are linking to.