Page tree
Skip to end of metadata
Go to start of metadata

When upgrading to 4.5 you should also be upgrading to Blossom 2.0. The naming convention for Blossom templates changed between versions 1.x and 2.0. The previous convention was to use the path of the controller with leading and trailing slashes removed and slashed within the name converted to underscores. In Magnolia 4.5 template ids are in the format of <moduleName>:<path>, as a consequence the blossom convention was updated and you now specify the id explicitly on your controller. Like so: @Template(id="myModule:pages/news", title="News").

There's no direct correlation from the previous convention to the new one. Therefor it's not possible for a script to automatically convert between them.

What you can do is write an update task that scans your pages and changes from the old names to the new ones you have annotated your class with. Such a task would go along these lines.

package info.magnolia.module.blossom.setup;

import java.util.Map;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import info.magnolia.jcr.util.NodeUtil;
import info.magnolia.jcr.util.NodeVisitor;
import info.magnolia.module.InstallContext;
import info.magnolia.repository.RepositoryConstants;

 * Maps from Blossom 1.x template ids to Blossom 2.0+ templates ids, that is: newsArticle to blossom:pages/newsArticle.
 * Using a mapping it iterates over the website repository and changes the template id for every node using one of the
 * older style template ids.
public class MigrateBlossomTemplates extends AbstractRepositoryTask {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private final Map<String, String> mappings;

    public MigrateBlossomTemplates(Map<String, String> mappings) {
        super("Migrate Blossom templates", "Migrates blossom templates to new naming conventions.");
        this.mappings = mappings;

    protected void doExecute(final InstallContext ctx) throws RepositoryException, TaskExecutionException {
        Session session = ctx.getJCRSession(RepositoryConstants.WEBSITE);
        NodeUtil.visit(session.getRootNode(), new NodeVisitor() {

            public void visit(Node node) throws RepositoryException {
                String currentTemplate = getTemplate(node);
                if (currentTemplate != null) {
                    String newTemplate = mappings.get(currentTemplate);
                    if (newTemplate != null) {
                        setTemplate(node, newTemplate);
                        if (logger.isDebugEnabled()) {
                            logger.debug("Changed template of node {} from {} to {}",
                                    new String[]{node.getPath(), currentTemplate, newTemplate});

    private void setTemplate(Node node, String template) throws RepositoryException {
        node.getNode("MetaData").setProperty("mgnl:template", template);

    private String getTemplate(Node node) throws RepositoryException {
        return node.hasProperty("MetaData/mgnl:template") ? node.getProperty("MetaData/mgnl:template").getString() : null;

1 Comment

  1. is it possible to use blossom 2.x with magnolia 4.4.x? if yes, how would this class look, how do you get the session, and so on?