user8417846
user8417846

Reputation:

How to use a FreeMarker template in a Magnolia App?

I'm using Magnolia 5.4 and have developed an app following the documentation: https://documentation.magnolia-cms.com/display/DOCS54/Apps

The app is being rendered correctly in the magnolia shell. Opening the app shows a «Hello World» message as described in the documentation: https://documentation.magnolia-cms.com/display/DOCS54/Programming+an+app#Programminganapp-MainSubApp

I've removed the unnecessary code and ended up with this:

public class HelloWorldMainSubAppViewImpl implements HelloWorldMainSubAppView {

    private VerticalLayout layout = new VerticalLayout();
    private Listener listener;

    public HelloWorldMainSubAppViewImpl() {
        layout.setMargin(true);
        layout.setSpacing(true);
        layout.addComponent(new Label("Hello World!"));
    }

    @Override
    public Component asVaadinComponent() {
        return layout;
    }
}

Instead of using the Label component I would like to use a FreeMarker template where I define a custom view.

Having read through the documentation I haven't figured out yet how to do this.

Upvotes: 0

Views: 1095

Answers (2)

user8417846
user8417846

Reputation:

Here is the solution to my problem, based on the previous work.

This is the «EmbeddedPageSubApp» approach as described under «Custom App»

  1. Create a regular page somewhere in your navigation.

  2. Open the Configuration app, go to /modules/<APP_NAME>/apps/<APP_NAME>/subApps/main and add a url property to the mainSubApp with an absolute path to the previously created page.

  3. Change value of the class property /modules/<APP_NAME>/apps/<APP_NAME>/subApps/main to info.magnolia.ui.framework.app.embedded.EmbeddedPageSubAppDescriptor

  4. Change the value of the subAppClass property to info.magnolia.ui.framework.app.embedded.EmbeddedPageSubApp

  5. If you don't want that page to be visible restrict its access within 'superuser' group / role so that only administrators can use it.

This binds that with an iframe. You should choose a blank template since the navigation elements of the embedded page are visible within the app.

Upvotes: 1

Ducaz035
Ducaz035

Reputation: 3132

I might be wrong here but to my knowledge Freemarker is only used to create templates and unfortunately limited to it. https://documentation.magnolia-cms.com/display/DOCS60/Template+scripts

On the other hand, What you want to do is to develop your custom app and here is an example of how to do that. https://documentation.magnolia-cms.com/display/DOCS54/My+first+content+app

Also, if you are motivated to move to latest Magnolia version, you can define your custom app pretty easily using Content Types.

Hope that helps,

Cheers,

Upvotes: 0

Related Questions