我是Hippo CMS的新手,并完成了本教程。一切顺利。但是,我有几个问题,希望得到答案。
1)我需要为我创建的每个文档创建一个新的控制器吗?或者我是否可以在一个控制器中为每个文档重复以下代码行:
Simpledocument document = (Simpledocument) ctx.getContentBean();
if (document != null) {
// Put the document on the request
request.setAttribute("document", document);
}
对于我而言,我不必为每个文档都创建一个新的控制器,这完全没有道理。这可能会变得混乱。
2)完成的在Hippo CMS Console中创建动态hello world文档的步骤。每个文档都必须遵循所有这些步骤吗?我有一种感觉。
public class SimpleComponent extends BaseHstComponent {
public static final Logger log = LoggerFactory.getLogger(SimpleComponent.class);
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();
// Retrieve the document based on the URL
HelloWorldTut document = (HelloWorldTut) ctx.getContentBean();
HelloWorldList docList = (HelloWorldList) ctx.getContentBean();
if (document != null) {
//Put the document on the request
request.setAttribute("doc", document);
request.setAttribute("docList", docList);
}
}
}
当然,HelloWorldTut和HelloWorldList是两种不同的文档类型。
答案 0 :(得分:0)
每个组件都需要一个控制器,一个页面可以包含多个组件。但是,当然可以重用代码和组件。根据从网址中匹配的站点地图项来呈现页面。这是附加到页面配置的,该页面配置定义了组件(或通道管理器中使用的组件的容器)。您甚至不需要每个文档一个sitemapitem。使用通配符,您可以根据模式匹配网址。
2)对于每种文档类型。如果必须为每个文档进行配置,它将很快变得难以管理。如果您拥有全部一种类型的文档,则可以每次都匹配到相同的页面配置。通过在sitemapitem中使用通配符并假定url与文档名称匹配,您可以匹配每个文档。
答案 1 :(得分:0)
我有一个类似的问题,今天在https://community.bloomreach.com/t/controller-for-every-view/744/3
得到了回答如果不需要自定义处理,则不必具有控制器。您可以使用<#assign document=hstRequestContext.contentBean />
在您查看模板中获取内容。