HubL is the jinja inspired templating language used for building templates and modules on the HubSpot CMS. If statements, for loops, includes, etc.
{%
. They do not print anything to the page.
{{
. For example, a variable must be defined as a statement, but then a HubL expression would be used to print the variable.
{% ... %}
; This can be used to modify lists and dictionaries.
Note: When adding to arrays, you want to use .append()
and when adding to objects, you want to use .update()
{#
.
primaryColor
is defined in a statement and then printed with a HubL expression. This example mixes the HubL variable with CSS.
datetimeformat
filter. You can view a full list of filters here.
if
, elif
, else
, and endif
. An if statement must begin with an if
and end with an endif
.
The example below defines a choice module that lets the end user select a department from a dropdown. Depending on what the user selects in the editor, the template will generate a dynamic heading for a careers page. This example requires the use of the export_to_template_context
parameter.
for
statement and end with an endfor
statement.
In the example below, an array of types of bears is stored as a variable called bears
. A for loop is then used to iterate through the different types of bears printing a list item for each type.
.html
files in one HubL template using the include tag. In order to create an HTML file that does not require the standard template variables, you must uncheck the option “Make template available for new content.” The syntax is displayed below:
standard_header_includes
and standard_footer_includes
variables. Within that template, you need to define a unique block using the following syntax where my_sidebar
is a unique name: