Reusing configuration
When developing a website or an application using Magnolia, it’s recommended to reuse existing components or entire pages from other projects.
This is particularly useful for accelerating development and maintaining consistency across different parts of your digital presence.
For instance, if you’re building a new section of your site and find that a page from the travel-demo
project, for example, its home page, already contains the layout, components, and content structure you need, you can leverage it.
This page gives an overview of how you can reuse configurations and override properties to customize them to suit your needs. Instead of copying specific instances of pages, you reuse the underlying YAML definitions or extend JCR-based items. You can only include or inherit the same type of configurations, such as dialog actions or form fields, into a dialog.
Reusing definitions
Within both JCR configuration and YAML files, you can use mechanisms to reuse existing configuration.
YAML include
Use !include
in a YAML file to reuse a snippet or a complete YAML-based configuration.
Reference the includable as Magnolia Resource (which can be from any origin).
!include:/mtk/dialogs/pages/basic.yaml (1)
form:
properties:
- name: title (2)
description: Some new description for the title (2)
1 | Includes the basic.yaml resource with the !include directive. |
2 | Modified properties in the included definition. |
Avoid adding YAML snippets, which are not proper definitions, to definition-specific folders like templates , dialogs , or apps .
Instead, place them in a folder that is not scanned, such as /<your-module>/includes/ .
|
For more details, see YAML include.
YAML inherit
Use !inherit
in a YAML file to inherit a registered definition item.
You can inherit on the root level only.
!inherit:module-a:components/a-component (1)
title: b-component (2)
description: This is a b-bombastic component to test cool YAML features! (3)
parameters:
color: red (4)
size: 100 (4)
1 | Inherit the a-component definition. |
2 | Override the title property. |
3 | Add a new description property. |
4 | Override the color and size properties. |
title: a-component
renderType: freemarker
templateScript: /module-a/templates/components/a-component.ftl
dialog: module-a:components/a-component
modelClass: info.magnolia.module.jsmodels.rendering.JavascriptRenderingModel
parameters:
color: blue
size: 50
For more details, see YAML inherit.
YAML override
The !override
directive prevents a node from inheriting properties from its original definition.
Therefore, you must explicitly define all necessary properties for the overridden node.
!inherit:module-a:pages/l-page
title: XS page
areas:
main:
availableComponents: !override (1)
linkList: (2)
id: my-module:components/myLinkList (2)
1 | The resulting definition ignores all the properties of availableComponents in the inherited l-page definition (textImage , teaser , image , and link ). |
2 | Only the myLinkList component is available in the main area. |
title: L page
templateScript: /mtk/templates/pages/basic.ftl
renderType: freemarker
dialog: module-a:pages/l-page
visible: true
areas:
main:
availableComponents:
textImage:
id: mtk:components/textImage
teaser:
id: mtk:components/teaser
image:
id: mtk:components/image
link:
id: mtk:components/link
JCR extends
The JCR extends mechanism is based on JCR nodes and properties. JCR configuration data can be extended on any node level, and thus on any level of configuration. JCR extends allow to extend sub-items of a JCR-defined item definition.
For more details, see JCR extends. |
Summary
The following table outlines the reuse commands, detailing their application and usage.
Reuse command | Context | Inheritance type | Override granularity | Typical use |
---|---|---|---|---|
|
YAML only |
Snippet/config fragment |
Node-level (inserted block) |
Share reusable chunks in a folder that is not scanned, such as |
|
YAML registry (root only) |
Whole definition |
Root-level, you can override keys |
Inherit whole definitions from the YAML registry. Registered items can originate from YAML files, JCR configurations, or even Blossom Java code. |
|
JCR (config workspace) |
Whole node/subtree |
Any node/property |
Runtime config & reuse, for example, extend a site definition and override locales. |
|
Whole definition |
Root-level, you can override any configuration with the same name |
What can’t be overridden?
Overriding is not possible in the following situations:
-
You can’t override list items due to their syntax. To bypass this constraint, use a YAML map instead of a list to apply an !override to an item. Even if the definition class expects a list, the YAML file can define the item with a map.
-
You can override Magnolia defaults within your module descriptors, but not observed components.
-
If automatic generation of references is turned off in the Headless Accelerator, reference resolvers can’t be overridden for specific properties.
In addition, the following properties can’t be overridden.
-
Unique and system IDs
-
Dialog, component, renderer, site, and page definitions require a globally unique and unchangeable
id
property. -
JCR node names must be unique within their scope and can’t be altered by inheritance or override.
-
-
Type/Class properties
-
The
$type
property in field and column definitions specifies a component’s unchangeable class. -
App and subapp descriptors also need fixed class properties for correct implementation binding.
-
-
Domain, mapping, group, row names
-
Domain mapping: Node and domain names in site definitions must be unique and constant for stable routing.
-
App Launcher: Critical structure names (
group
,row
) can’t be overridden without breaking the layout.
-
-
Field and area names must be unique within their container and can’t be redefined by inheritance.
What can be overridden?
The table below lists standard properties across the most used configuration definitions. All items that can be configured via YAML are registered in a specific registry. Registered items can be viewed in the Definitions app.
Definitions | Example properties | Standard properties |
---|---|---|
Follow this link for a full example definition.
|
Organizes apps into rows and groups so users see apps grouped by purpose (for example, editors, developers) with a customized layout.
|
|
Follow this link for full details on content type-based configuration and a fully manual app configuration.
|
Defines the core properties and behavior of an application, including its appearance, permissions, and available sub-applications.
|
|
Go to Subapp descriptor properties for more details. Exmaple descriptor definition below.
|
Defines a subapp tab within an app. Controls its data source, tab label/icon, available actions, and whether the tab can be closed.
|
|
Go to Workbench properties for more details.
|
Defines the main browsing area of a content app: which content views are available and any optional extension panels, plus sizing and naming.
|
|
Go to Content view properties for more details.
|
Defines a view inside the workbench (tree, list, or thumbnail), including its columns, drag-and-drop behavior, selection, and display options.
|
|
Go to Column properties for more detais.
|
Configure column display, editing, filtering, width, and sorting options.
|
|
Go to Datasource types for more general details or JCR example definition for a full JCR datasource example.
|
Connect apps, subapps, and fields to a persistence layer such as JCR.
|
|
Follow this link for a full example definition.
|
Organizes actions into sections and groups and defines when each section is displayed.
|
|
Go to General action properties for more details.
|
Configures an executable UI action (for example, add, edit, publish).
|
|
Follow this link for a full example definition.
|
Controls site-wide settings, including available page templates, theme, locale, and routing (URL mapping).
|
|
Go to Mappings configuration for more details.
|
Specifies the content mapping, for example, the
|
|
See Configuring a renderer for more details.
|
Register a rendering engine and optional context attributes.
|
|
Go to CSS Files, JavaScript files, or Image variations for more details.
|
Defines site-wide CSS, JS resources, and imaging variations.
|
|
Go to Page template properties for more details.
|
Defines a page template, its script, areas, and availability.
|
|
Go to Area properties for more details.
|
Defines editable regions of a page/component and which components are allowed.
|
|
Go to Component properties for more details.
|
Defines a component with its own script and dialog.
|
|
Follow this link for a full example definition.
|
It defines the fields, tabs, actions, and layout for dialogs that editors use to input and manage content.
|
|
Refer to specific field pages, for example Text field, Link field, Multi field, or Checkbox field.
|
Defines form input, which is used in dialogs, where authors can enter content.
|