我搜索在玉蘭呈現具體內容,如與渲染引擎組件,以便我發現計算器這個話題:Programatically render template area in Magnolia CMS編程方式呈現模板區玉蘭CMS
我的問題是有關以下類的結構:FilteringAppendableWrapper和 FakeResponse:用來放在AppendableFilteringResponseOutputProvider
感謝所有幫助僞造的HTTP響應。
我搜索在玉蘭呈現具體內容,如與渲染引擎組件,以便我發現計算器這個話題:Programatically render template area in Magnolia CMS編程方式呈現模板區玉蘭CMS
我的問題是有關以下類的結構:FilteringAppendableWrapper和 FakeResponse:用來放在AppendableFilteringResponseOutputProvider
感謝所有幫助僞造的HTTP響應。
你想問一下呢?爲什麼他沒有使用真實的迴應?因爲他正在僞造整個(web)請求到一個頁面,然後從他的「FakeResponse」獲得輸出並將其添加到json數組以填充REST請求的響應正文。我個人認爲這樣的解決方案對於這項工作來說是過分的,如果我必須這樣做,我可能會簡單地爲組件或整個頁面註冊變體模板,並且當請求帶有.ajax的擴展我會有我的變化踢和整個頁面(或區域或組件)作爲一個JSON數組。
HTH,
揚
沒有必要對假響應。這個簡單的代碼工作得很好:
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());
你能解釋什麼是變異模板,如果有可能給我一個例子。我是新來的Magnolia,謝謝。 –
嘿,簡,你是不是這個意思? Session session = MgnlContext.getJCRSession(「website」); \t \t \t 節點含量= session.getNode( 「/ protoTest /內容/ 02」); \t \t \t componentDefinition = templateDefinitionAssignment.getAssignedTemplateDefinition(content); \t \t \t 的OutputStream的OutputStream =新ByteArrayOutputStream(); \t \t \t OutputStreamWriter作家=新OutputStreamWriter(OutputStream中); (內容,組件定義,新的HashMap <字符串,對象>(),新的AppendableOnlyOutputProvider(作家)); –
不,這不是我的意思。木蘭允許你爲相同的內容定義多個模板定義,然後基於例如您可以通過該擴展來請求資源,您可以控制該資源將以何種格式呈現。有關更多詳細信息,請參閱https://documentation.magnolia-cms.com/display/DOCS53/Configuring+variations+in+a+page+template。 – Jan