Using drag and drop areas to support content creators easily making layout, style and content changes
Create a new HTML template
{{ require_css() }}
.Create a drag and drop area
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.Create a section with a module
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.max_width
on the dnd_section
is affecting the content.Include multiple modules
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.vertical_alignment
on the dnd_section
is vertically centering our content.Incorporate columns and rows
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.Set generic drag and drop component styles
dnd_sections
with the CSS:.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() }}
.