Skip to main content

Supported products

Requires one of the following products or higher.

  • Content Hub -Professional
  • Marketing Hub -Professional

Drag and drop areas are sections of a template that act as empty containers that can be modified directly from the page editor. By building drag and drop areas into a template, it enables content creators to add and manage modules in the page editor as needed, rather than relying on static modules built into the template.

Animation of modules being dragged onto a page, with columns and rows being adjusted

In addition to using drag and drop areas as empty drop zones for content creators, you can also pre-populate drag and drop areas with various modules, layouts, and content to act as a starting point.

This tutorial will take you through setting up a simple drag and drop area. For more developer resources on drag and drop areas, see the boilerplate for best practices on implementation as well as the drag and drop area HubL tag reference documentation.

Create a new HTML template to contain the HubL and HTML which will make up your drag and drop section.

A dnd_area is the container that makes a portion of the web page editable in terms of its structure, design, and content. The body of a dnd_area tag supplies the default content for the drag and drop area.

This tag on its own will generate a drop zone for content creators to drag modules into within the content creator.

A dnd_section is a top-level row, and can only be a direct child of a dnd_area. Sections support a variety of parameters that control default values for stylistic controls content creators have for sections within the content creators.

As an example, the code below creates a section with a background image (background_image). This section is centered by a vertical-alignment parameter, and has a max width of 1000px field for child content. For a full list of supported parameters on the drag and drop HubL tags, see the drag and drop area HubL tag reference documentation.

To pre-populate the section with content, the code also includes a dnd_module tag to include a module by referencing its path. For this example, the dnd_module is pulling in HubSpot's default rich text module, as set by the path parameter. A default value for the rich text module is specified using the module_attribute tag.

This results in the drag and drop area containing a module that content creators can edit within the content editor. Note how setting the max_width on the dnd_section is affecting the content.

screenshot of the page editor with the module toolbar displaying

To include more than one module, use multiple dnd_module tags. By setting the offset and width parameters, which are based off of a 12 column grid, you can place an image module next to the rich text module, as shown below.

Now the page has an editable image module as well as a drag handle, allowing content creators to change the width and offset of the modules. Note how setting a vertical_alignment on the dnd_section is vertically centering our content.

screenshot of page editor showing an image module added to a section

To make the drag and drop area more complex, you can incorporate rows and columns using the dnd_row and dnd_column tags. Rows and columns act similarly to sections in the content editor, where content creators can drag them around, as well as clone, delete, and style them.

Now, content creators will have further stylistic and layout control over specific rows and columns, in addition to modules and sections.

screenshot of page editor showing a row with two columns, an image module left, rich text module and form module on right.

The various components of drag and drop areas, sections, columns, rows and modules all have classes which can be styled using CSS. The editable styles and options for these components can be set using CSS rather than HubL. For example, default padding can be set on dnd_sections with the CSS:

The generic CSS selectors for the drag and drop area components are .dnd-section, .dnd-column, .dnd-row and .dnd-module. Aside from these dnd prefixed classes, the actual grid class names in the markup are based on bootstrap 2 names. This does not mean you need to use bootstrap 2 with drag and drop areas. When you add a dnd_area to your page, you are responsible for providing the styles that make the grid work. An example of layout styles you could implement can be found in the HubSpot CMS boilerplate. Your stylesheet can be added to the template using {{ require_css() }}.