Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed the theme topic to YAML (copied from DOCS55)

...

A site definition allows you to add features such as image variations to your site. This page explains how to configure image variations in a theme, part of the which is referenced in the site definition.

Before you proceed read How to work with images using damfn.

...

The image assets for Eric's cars are rather large. The components on the page require smaller images. Even if Bootstrap CSS resizes the images to fit the layout, the browser still loads the big images. We want to render small images on the page but we want to keep the big original images in the Assets app in case we use them elsewhere.

Info
iconfalse
titleBest practice

Excerpt Include
How to work with images using damfn
How to work with images using damfn
nopaneltrue

...

Configuring a theme

Open the Site app. It may already contain a site configuration, for instance for the travel demo. (Keep in mind that you can only have only one site with Magnolia Community Edition.) In  In this tutorial we add a new theme to an existing and reference it in the existing travel site definition.

Go to the Themes tab and build the following structure:

...

enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse

...

Mgnl n
my-first-website

...

Mgnl n
imaging

...

Mgnl n
variations

A theme can be configured in YAML in any module and must reside in the themes folder of the module. 

Create a themes folder in /one-pager-module:

Code Block
 one-pager-module/
├── dialogs/
└── templates/ 
└── themes/ 
	└── my-first-website.yaml
└── webresources/   

Defining image variations in a theme

Create my-first-website theme definition with three image variations : Add three image variations : largelarge-square and  and xxlarge.

info.magnolia.templating.imaging.variation.SimpleResizeVariation

      width: 730
    large-square:
      class: info.magnolia.templating.imaging.variation.SimpleResizeVariation

      width: 730
      height: 730
    xxlarge:
      class: info.magnolia.templating.imaging.variation.SimpleResizeVariation

      width: 1140
Advanced Tables - Table Pluscode
enableHeadingAttributeslanguagefalseyaml
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
title/one-pager-module/themes/my-first-website.yaml
imaging:
  class: info.magnolia.templating.imaging.VariationAwareImagingSupport
  variations:
    large:
      class: 
Node nameValue

Mgnl n
variations

 

Mgnl n
large

 

Mgnl p
class

Mgnl p
width

730

Mgnl n
large-square

 

Mgnl p
class

Mgnl p
width

730

Mgnl p
height

730

Mgnl n
xxlarge

 

Mgnl p
class

Mgnl p
width

 1140

Referencing a theme

Themes are referenced in the themes node of a site definition which is configured in the Site app

Open the Site app and change the value of the /theme/name property to my-first-websiteIn the Site Definitions tab configure the site definition to use the new theme:

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl n
templates


Mgnl n
theme

 

Mgnl p
name

my-first-website

Mgnl n
i18n


Using image variations

Although we did not mention it, the code in the previous pages already uses imaging variations. The damfn templating functions return resized images when you pass the desired variation name as an argument:

...

To render the background image we pass the variation name xxlarge:

Code Pro
languagexml
titletemplates/pages/main.ftl
sections%%(<style>)%% - %%</style>%%
urlhttps://git.magnolia-cms.com/projects/DOCUMENTATION/repos/my-first-website-tutorial/browse/light-modules/one-pager-module/templates/pages/main.ftl?at=master&raw
 

Product image

To render a car image we use the large variation:

Code Pro
languagexml
titletemplates/components/content-items-list.ftl (fragment)
sections%%(<div class="big-box">)%% - %%(</div>)%%
urlhttps://git.magnolia-cms.com/projects/DOCUMENTATION/repos/my-first-website-tutorial/browse/light-modules/one-pager-module/templates/components/content-items-list.ftl?at=master&raw
 

Image in the textImage component

The macro that renders Eric's profile image uses the large and large-square variations depending on what the user has selected in the dialog:

Code Pro
languagexml
titletemplates/components/textImage.ftl (fragment)
sections%%(roundedEdges)%% - %%(#if)%%
urlhttps://git.magnolia-cms.com/projects/DOCUMENTATION/repos/my-first-website-tutorial/browse/light-modules/one-pager-module/templates/components/textImage.ftl?at=master&raw
 

What happens if no variation is defined?

...

How can you test that the variations are working. ? Does Magnolia now resize the images?

...

Example: The original Fiat Cinquecento image is 1024 x 741 pixels. Magnolia resizes it to 730 pixels as defined in the large variation. Boostrap resizes the image further to fit the parent element in a responsive way.

 


Congratulations! (big grin)

You created a website with Magnolia. You know how to manage content in an app and how to display it on the site. You created your first light module and learned the basics of working with images.

See Tutorials for your next learning goal.