mercury_editor_page_templates
A Drupal module that provides a template system for creating pages with pre-configured layouts and content using Mercury Editor.
Overview
Streamlines page creation by providing pre-defined templates that integrate
with Mercury Editor. Content creators can select templates when creating new
pages, ensuring consistency and reducing setup time. Editors with the right
permissions can also capture any existing page layout as a new reusable
template directly from the editor toolbar.
Features
- Template Management: Create, edit, delete, and disable page templates via the admin interface
- Save as Page Template: Capture the current page layout as a reusable template without leaving Mercury Editor
- Template Groups: Organise templates into labeled, sortable sections in the template selector
- Within-group ordering: Drag-and-drop reordering of templates inside each group
- Content Type Integration: Configure templates for specific content types
- Preview Images: Optional per-template image (PNG, JPEG, or WebP) shown in the template selector
- YAML Configuration: Define templates using YAML for easy editing and version control
- Flexible Field Support: Support for any field machine name and structure
- Nested Paragraphs: Support for complex nested paragraph structures
- Reference Fields: Resolve entity reference and paragraph references from YAML using lookup keys
- Region Support: Layout regions for content placement
- Mercury Editor Integration: Seamless integration with Mercury Editor
Requirements
- Drupal 10.x or 11.x
- layout_paragraphs: ^2.1
- mercury_editor: ^2.0
- paragraphs: ^1.15
Installation
composer require drupal/mercury_editor_page_templates
drush en mercury_editor_page_templates
Quick Start
- Configure Mercury Editor: Set up content types in Mercury Editor settings
- Create Templates: Go to Configuration > Content authoring > Mercury Editor Page Templates and add templates with labels, content types, and paragraph structure
- Organise Templates: Use the Groups tab to create labeled sections, then assign templates to groups and drag rows to set their order
- Use Templates: When creating content, select from available templates in the template selector
- Save from the Editor: With an existing page open in Mercury Editor, click Save as Page Template in the toolbar to capture the current layout as a new or updated template
Save as Page Template
Editors with the Administer Mercury Editor Page Templates permission can
capture any open page as a reusable template from the Mercury Editor toolbar.
The dialog supports three modes:
- New template: Enter a label, machine ID, optional description and group, then click Save
- Update existing: If the page was originally created from a template, the dialog offers a one-click Update for that template
- Confirm overwrite: If the machine ID entered matches an existing template, a confirmation step is shown before overwriting
Paragraph field values, style options, layout sections and regions, and nested
paragraphs are all captured from the live Layout Paragraphs tempstore at save
time.
YAML Template Example
-
type: custom_section
description: 'Main Content Section'
layout: two_column_75_25
paragraphs:
-
type: content_block
description: 'Content block with title and body in the first region'
field_config:
-
field_name: field_title
field_structure:
value: 'Welcome to Our Site'
-
field_name: field_body
field_structure:
value: 'This is the main content area.'
format: full_html
style_options:
background_color: 'Light Blue'
text_alignment: 'Left'
padding_size: 'Medium'
region: first
-
type: text_block
description: 'Sidebar text block'
field_config:
-
field_name: body
field_structure:
value: 'Sidebar content.'
format: full_html
style_options:
background_color: 'bg-light border-2'
text_alignment: 'text-center font-bold'
region: second
Troubleshooting
Templates not showing?
- Ensure the content type is configured in Mercury Editor
- Check the template is assigned to the correct content type and is not disabled
- Validate YAML syntax
Save as Page Template button not visible?
- Ensure the user has the Administer Mercury Editor Page Templates permission
- Confirm the page is open in Mercury Editor (not the standard node edit form)
YAML errors?
- Use 2-space indentation
- Check for missing colons after field names
- Validate with an online YAML validator