CMS-General

Create and edit modules

Last updated: May 10, 2019

Applies to:

Marketing Hub  Professional, Enterprise
Legacy Marketing Hub Basic

In the design manager tool, you can create custom coded modules to add custom or advanced features to your blog, pages, or emails. The module editor has three editor panels for writing HTML and HubL, CSS, and JavaScript. Custom modules offer a wide range of functionalities so that content can be fully customized within the page, email, or blog editor. You can build custom modules from scratch or add pre-built modules to your account from the HubSpot Marketplace.

Please note: creating modules requires knowledge of HTML, CSS, HubL and the HubSpot design manager. It's recommended to work with a designer to create coded modules.


Create a new module

  • In your HubSpot account, navigate to Marketing > Files and Templates > Design Tools.
  • At the top of the finder, click the File dropdown menu and select New file.

new-file

  • In the dialog box that appears, select Module.

create-new-file-module

  • Choose whether you want to use this module in page templates, blog templates, and/or email templates.

Please note: there are technical differences between these module types that make them incompatible. For example, CSS and JavaScript will be disabled if you select Email templates for email compatibility.

  • Select if you'd like the content scope of the module to be a local module or global module. If you create a global module, editing this module's content will update every location where the module is used. Learn how to work with smart content in a global module.
  • Give the module a file name, then click Create.

set-up-your-new-module

Add fields to your module

  • In the module inspector on the right, click the Add field dropdown in the Fields section, then select a field to add to your module.

module-add-field

  • You can edit the name of your field by clicking the pencil icon edit next to the field name. To edit the HubL variable name, make your changes in the HubL variable name text field. 

Add field default content

In the Content Options section, you can add default content that appears when the module is used in templates and content editors. The options for default content will differ depending on the field type.

In the example below, the field type is an image field, so the default content options are to select a default image and hide size controls.

field-content-options

Set field editor options

In the Editor Options section, you can enable the following options:

  • Make this field required: the user will not be able to leave this field blank.
  • Prevent editing in content editors: the field content cannot be edited by end users when the module is selected in the content editor. The field content is still editable at the template level. This option is not available for global modules, which cannot be edited on the page level.
  • Help text: add help text to the field to give users context or instruction.

field-editor-options

Set field display conditions

You can customize a module field to only appear if another field meets certain criteria with field display conditions.

  • In the Display Conditions section, click the HubL variable dropdown menu to select a module field, then click the is not empty dropdown to choose the condition for that field.
  • If you select the condition is equal to, enter a value or regex.

In the example below, display conditions are being set for an image field. The condition is that the value in image_title (a text field) must be equal to Headshot in order for the image field to appear in the module.

field-display-conditions

The display conditions will be automatically enabled once you've set a condition. To disable the display conditions, click the toggle switch on the right of Display Conditions.

Set field repeater options

Lastly, you can set repeater options for your field. Repeaters are fields and groups that can create multiple objects and display them using a for loop.

  • In the Repeater options section, select a minimum and/or maximum number of required instances of this field.
  • You can also choose to set a default object count, which will be the number of instances of the field that will appear by default in the module.

In the example below, the image field is being set up as an image slider. The object count limits are set so a minimum of image fields will appear in the module, up to a maximum of 5 image fields. A user will see image fields appear in the module by default, and can choose to add one more image field or remove one existing image field.

field-repeater-options

The repeater options will be automatically enabled once you've modified one of the options. To disable the repeater options, click the toggle switch on the right of Repeater Options.

Learn more about field repeating and loops in the designer documentation.

Copy and paste your field snippets

  • When you're ready to incorporate one of your custom fields into your module, copy and paste the field snippet into the module's HTML + HubL editor.
    • If you're in the field inspector, click Copy snippet on the right of the field's HubL variable name.
    • If you're in the module inspector, hover over the field and click the Actions dropdown, then select Copy snippet.
  • Click into the location you'd like to add the field in the HTML + HubL editor, then paste the snippet by pressing Ctrl+or Cmd+V.

copy-paste-field-snippet

Write your module syntax

As you edit your module, you can write additional module syntax in the HTML + HubLCSS, and JS editor panes. Learn more about the module code editor and module syntax reference in HubSpot's designer documentation.

Preview your module

You can preview how your module will appear and work in a content editor by clicking the Preview button at the upper right of the module editor. The preview of your module will open in a new tab. This preview syncs with the editor and will automatically refresh as you work.

preview-module

Publish your module

Once you're done adding fields, writing your module syntax, and are satisfied with how the module appears and works in the preview, you can proceed to publish your module. In the upper right, click Publish changes.

publish-module

Make your module available for templates

  • Switch the Make available for templates toggle on at the top of the editor to make this module available to add to your templates.

content-toggle

  • Switch this toggle off to make changes or test the module's functionality. If this toggle is disabled, your team will see an alert that this module is not available for templates.

make-module-available

Add your module to a template

  • In the template layout editor, click the Add tab at top of the layout inspector, then search for your module. Custom modules that you've created can be identified by the custom module icon customModules.
  • Drag and drop the module into your template.

add-custom-module

Add or purchase a module from the Marketplace

In addition to creating your own modules, you can add or purchase custom modules that other users or providers have created in the HubSpot Marketplace.

  • In your HubSpot account, navigate to Marketing > Files and Templates > Template Marketplace.
  • In the Filter products section on the left, click the All products dropdown under Category and select Modules.You can filter the available modules according to:
    • Price: select if the module is free or paid
    • Functionselect the type of function(s) the module includes (e.g. calculator, gallery, map)
    • Works with: select the template type(s) the module can be used in
    • Provider: select the provider(s) the module is offered by
  • Once you've decided on a module, hover over it and click View details.
  • Click Get module for free or Buy module for $x at the upper right. If the module is free, it will automatically be added to your design manager. If the module is paid, proceed to enter your payment details.
  • Once payment has been processed, the module will be added to your design manager.