This page describes how to define and render custom content blocks that
can be grouped to form content compositions in implementations of the
Content editor.
The Magnolia Stories app, which is
an implementation of the content editor, uses four predefined block
types: text, image, externalLink and video.
Block types
The Content editor provides predefined block types that you can use in
your custom content editor app:
text
image
externalLink
video
You can also define your own blocks.
Compared to
TextFieldDefinition,
the text block implements a special RichTextBlock class, which
features basic text formatting functions:
All the other predefined block types implement the
FieldSetBlockDefinition class.
Demo block types
The Magnolia demo decorates the default Stories app and provides two
additional block types you can use:
tour
date
Both block types implement the FieldSetBlockDefinition class.
This section explains how to render block content in a page or a
component template.
The cms:block directive
The Content editor module provides cms:block, a Magnolia FreeMarker
directive for fetching and
rendering block elements.
The directive expects a node of the type mgnl:block as argument,
identifies the template definition of the block and calls the associated
template script.
Block-rendering scripts in the article-editor submodule
In /templates/pages/areas, the article-editor submodule already
contains the following predefined block-rendering scripts used by the
Stories app:
articleDisplayArea.ftl – Displays a single story.
articleListArea.ftl – Displays a list of all story.
articleReferenceArea.ftl – Displays a referenced story through the
/templates/pages/article.inc.ftl page template script.
Examples of block rendering
The examples show how to render blocks within a
template script of a page or
component template. Using the Magnolia directive cms.block, the
template script of the block is executed during the rendering of the
page or component.