以编程方式渲染Magnolia CMS中的模板区域

时间:2015-12-17 14:36:34

标签: rendering render andengine magnolia

我使用Render Engine在Magnolia中搜索渲染特定内容,因此我在stackoverflow上找到了这个主题:Programatically render template area in Magnolia CMS

我的问题是关于以下类的结构:FilteringAppendableWrapper和 FakeResponse:用于在AppendableFilteringResponseOutputProvider中放置假Http响应

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

不需要虚假回复。这个简单的代码很好用:

        Session session = MgnlContext.getJCRSession("website");

        Node content = session.getNode("/protoTest/content/01");

        componentDefinition = templateDefinitionAssignment.getAssignedTemplateDefinition(content);

        OutputStream outputStream = new ByteArrayOutputStream();

        OutputStreamWriter writer = new OutputStreamWriter(outputStream);

        appendable = new AppendableOnlyOutputProvider(writer);

        renderingEngine.render(content, componentDefinition, new HashMap<String, Object>(), appendable);

        ((Writer) appendable.getAppendable()).flush();

        System.out.println(outputStream.toString());