Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Note

If you for some reason do not have the Stories App, add this to your webapp pom:

Code Block
<dependency>
  <groupId>info.magnolia.editor</groupId>
  <artifactId>stories-app</artifactId>
  <version>1.1.5</version>
</dependency
Expand
titleCreate the module structure we will need:
Code Block
languagebash
cd my-light-_modules
mkdir -p block-examples/blocks
mkdir -p block-examples/templates/blocks
mkdir block-examples/i18n
mkdir -p block-examples/decorations/stories-app/apps/
mkdir -p block-examples/templates/pages

Alternatively, use mgnl create-light-module and add the structure you need.

Expand
titleAdd the block definition:
Code Block
languageyaml
titleblock-examples/blocks/quote.yaml
class: info.magnolia.editor.block.stock.FieldSetBlockDefinition
templateId: block-examples:blocks/quote
fields:
  quotation:
    class: info.magnolia.ui.form.field.definition.TextFieldDefinition
    rows: 3
  citedPerson:
    class: info.magnolia.ui.form.field.definition.TextFieldDefinition

...

Expand
title(Optional) Add internationalized labels:
yaml
Code Block
language
titleblock-examples/i18n/example-blocks_en.properties
blocks.quote.label=Quote
quote.quotation.label=Quote
quote.citedPerson.label=Cited person
Code Block
languageyaml
titleblock-examples/i18n/example-blocks_de.properties
blocks.quote.label=das Zitat
quote.quotation.label=das Zitat
quote.citedPerson.label=zitierte Person
Expand
titleDecorate the Stories app to allow it to use our new block type:
Code Block
languageyaml
titleblock-examples/decorations/stories-app/apps/stories.yaml
subApps:
  editor:
    contentDefinition:

      blocks:
        - text
        - image
        - video
        - externalLink
        - quote
Expand
titleAdd a story:

Add a title and lead text:

Add the url:

Image Added

Add a new quote block:

Add the url:

Image Removed

Add the quote:

Click Save and Publish

Expand
titleAdd page template definition and script to use the block:
Code Block
languageyaml
titleblock-examples/templates/pages/block.yaml
renderType: freemarker
title: Block Page
templateScript: /block-examples/templates/pages/block.ftl
Code Block
languageyaml
titleblock-examples/templates/pages/block.ftl
[#assign testContent = cmsfn.contentByPath("/test", "stories") /]
[#assign blocks = cmsfn.children(testContent, "mgnl:block") /]

<!DOCTYPE html>
<html xml:lang="en" lang="en" class="no-js">
    <head>
        [@cms.page /]
    </head>
    <body>
        [#if testContent?hasContent]
            [#if testContent.title?hasContent]
                <h2>${testContent.title}</h2>
            [/#if]
            [#if testContent.lead?hasContent]
                <h4>${testContent.lead}</h4>
            [/#if]
            [#assign blocks = cmsfn.children(testContent, "mgnl:block") /]
            [#list blocks as block]
                [@cms.block content=block /]
            [/#list]
        [/#if]
    </body>
</html>
Expand
titleAdd a page using the new block type:

Image Added

Click Next and then preview the page you just added.  The quote you entered earlier should be displayed:

Image Added

Expand
titleResulting directory structure:
Code Block
languagebash
block-examples/
├── blocks
│   └── quote.yaml
├── decorations
│   └── stories-app
│       └── apps
│           └── stories.yaml
├── i18n
│   ├── example-blocks_de.properties
│   └── example-blocks_en.properties
└── templates
    ├── blocks
    │   ├── quote.ftl
    │   └── quote.yaml
    └── pages
        ├── block.ftl
        └── block.yaml


Page Turner
button-linkstrue
YZ