Magnolia 4.5 reached end of life on June 30, 2016. This branch is no longer supported, see End-of-life policy.
Reusing content in more than one location on a website is a common scenario. The objective is to either render the same page in multiple locations or the same component on multiple pages.
Common content should be editable in one location and changes should propagate to affiliate sites immediately. Links pointing to other pages should continue to work when content is reused away from its original context. The content should adhere to the target site theme and pages should appear in navigation when rendered on target site.
Example usage: Acme Inc. has three affiliates: Europe, Asia and Australia. All four websites are managed in Magnolia. The affiliate sites need to render the Privacy Policy page from the parent company site verbatim.
The following approach retrieves content from the source page main
area and renders it in the target page main
area.
This example is NOT a complete solution. It is just a starting point for your own customization.
To configure a reuse page template:
stkReuse
in any folder, for example in /functional
. You can copy and amend a current dialog, for example /pages/section/stkSectionIntro
.edit
control for the page title.uuidLink
control that allows the user to select the source page to be reused. Name the control sourcePage
. The control will save the source page UUID to a property of the same name./templating-kit/pages/functional
:reuse
.main
area in the new template and shows how to use the stored value of the UUID link control to render the selected page content./pages
:stkReuse
. You can copy and amend /pages/stkSection
.title
property to Reuse
so you can identify the new template in Website./areas/main
node so that it contains only the following two properties:dialog
set to standard-templating-kit:functional/stkReuse
. Created in 1.templateScript
set to /templating-kit/pages/functional/reuse.ftl
, Created in 2./default/templates/availability/templates
make the new template available to all sites:stkReuse
./stkReuse
add a data node id
and set the value to standard-templating-kit:pages/stkReuse
.Example script:
<div id="main" role="main"> [@cms.area name="breadcrumb" content=content/] [@cms.area name="intro" content=content/] [@cms.area name="content"/] [#if content.sourcePage?has_content] [#assign node=ctx.getJCRSession('website').getNodeByIdentifier(content.sourcePage)] [#assign map=cmsfn.asContentMap(node)] [#if cmsfn.editMode] <a href="${cmsfn.link(node)}" class=""><span>Original page content from: ${map.title!map.@name}</span></a> [/#if] [#assign cnt=node.getNode('content')] [@cms.area name="content" content=cmsfn.asContentMap(cnt) /] [/#if] </div><!-- end main -->
Download the configuration used in this example as XML files:
stkReuse
template to the target page.Content from main
area of the source page is rendered in the target page main
area.
Reusing components can be done with inheritable components. This functionality is built in the STK. Inheritance is enabled on an area level in the /areas
node of the template definition. There are two options:
The limitation is that configured inheritance works only down a particular branch of the site. Inheriting a component from another branch or from a different site needs a custom solution.
Example usage: A sports news website is running special coverage on the upcoming Formula One Grand Prix. Site editors want to display a team standings component in the sidebar. Editors want to edit the component in once place and have it displayed on multiple pages, not all of which are in the same branch.
The recommended approach is to store and edit reusable component content in a separate website structure that is not visible on a public instance. This can be a branch within the same site or a completely different site root. Storing the reusable content in the Data module is also possible.
Following the example of Reusing pages above, create a:
A control that invokes the JCR website browser can be added to a dialog. Components are represented as numbered content nodes under the page area nodes, allowing for a specific component to be selected. In the example below, the page area /demo-project/news-and-events/news-overview/news01/content
has two components denoted as 0
and 00
.
1 Comment
Tobias Mattsson
To render components from an area on another page here's what you'd do: