How to use a FreeMarker template in a Magnolia App?

你说的曾经没有我的故事 提交于 2019-12-13 03:04:23

问题


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.


回答1:


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.




回答2:


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,



来源:https://stackoverflow.com/questions/56477989/how-to-use-a-freemarker-template-in-a-magnolia-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!