Versions Compared

Key

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

adapted from https://documentation.magnolia-cms.com/display/DOCS56/Developing+and+rendering+custom+content+blocks


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/
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
titleAdd the template definition:
Code Block
languageyaml
titleblock-examples/templates/blocks/quote.yaml
templateScript: /block-examples/templates/blocks/quote.ftl
renderType: freemarker
Expand
titleAdd the template script:
Code Block
languageyaml
titleblock-examples/templates/blocks/quote.ftl
[#if content.quotation?has_content]
<blockquote>
<p>${cmsfn.decode(content).quotation}</p>
    [#if content.citedPerson?has_content]<cite>${content.citedPerson}</cite>[/#if]
</blockquote>
[/#if]
Expand
title(Optional) Add internationalized labels:
Code Block
languageyaml
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








YZ