Welcome to the Hello Magnolia tutorial for front-end developers!
In this tutorial, you will download a fully functional light module to
your file system and view the result in Magnolia. You will then make
some changes in the files and see the impact your changes have.
Extract it to /Users/<username>/dev/light-modules/ if you followed the
example in
Install
Magnolia, or to the location where you decided to put your
light-modules folder.
Remove the version number from the extracted folder name. It
should be just hello-magnolia.
Magnolia is ready to use and gives you a list of suggestions to get started.
View the module files in the Resource Files app
Open the Resource Files app and see the resource files that make up the
hello-magnolia light module.
Search for apps or for content across all your apps using the Find Bar.
Open an app directly from the Find Bar using the command open <app-title> app, for example, type open pages app.
You must use the exact app title, as it appears in the App Launcher.
Note the file icon in the Origin column indicating that these
resources are file-based. You can double click on any resource to view
it directly in Magnolia.
Key templating files
Every Magnolia template needs a definition and a script. A template
definition gives the template a name and makes it available to the
system. Here we use YAML to create template
definitions. The template definition also tells the system which script
renders the content.
The template script contains the rendering instructions. A script can be
completely static but it usually includes editable content fragments or
other dynamically assigned values provided by
templating
functions (for instance
cmsfn to
fetch content) or
Rendering
context objects. Here we use
FreeMarker to create template
scripts.
Dialogs enable editors to enter content to be displayed by a template. A
template definition can reference a dialog definition (also YAML-based)
that specifies the input fields to displayed to editors.
Use the template in a page
You can use the templates provided by the hello-magnolia light module
right away:
Open the Pages app.
Create a new page.
Enter Hello Magnolia as the Page name.
Select the Hello template introduced by your light module and click
Next.
Enter Hello Magnolia as the Title and
This page was created using the hello template as the Introduction
text and click Save.
Open the page for editing.
Add a component to the page
The Hello Magnolia light module contains a component called quotation.
Add this component to the page you created:
Click on the New main component bar in your Hello Magnolia page.
In the Quotation dialog box, enter your favorite quote and the
author.
Tweak your light module
Now that you have seen the hello-magnolia light module working in
Magnolia, make some changes. You will see Magnolia automatically detects
any changes you make in your file system.
Add a new field to the component dialog
Currently, the component dialog definition provides two fields:
quotation and citedPerson.
Edit your component on your Hello Magnolia page. You see the field you
added at the bottom of the dialog.
You must now change the template script to render this new content on
the page.
Update the component template script
When rendering content you should test whether it exists. At the moment,
at least the quotation must exist, otherwise the whole component will
not be rendered. Take a look at your quotation.ftl file:
Walks you through the basic steps and commands required to create a
Magnolia light module using our CLI and reuse an existing module from
npm.
Working with
images in Magnolia - Learn how to handle images with Magnolia,
including both storing the image or a reference to an asset with a
dialog and rendering the image in a template script.