[MGNLSTK-699] Use Content2Bean to instantiate a site's template prototype Created: 04/Nov/10 Updated: 05/Nov/10 Resolved: 05/Nov/10 |
|
| Status: | Closed |
| Project: | Magnolia Standard Templating Kit (closed) |
| Component/s: | templates |
| Affects Version/s: | 1.3.5 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Critical |
| Reporter: | Vivian Steller | Assignee: | Philipp Bärfuss |
| Resolution: | Not an issue | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Template: |
|
| Acceptance criteria: |
Empty
|
| Date of First Response: |
| Description |
|
Currently C2B is not used to instantiate the site's prototype, which is sad. Developers expect being able e.g. to use the "class" nodedata to switch the implementation of an area (e.g. the header). Instead (if you're lucky, e.g. for header, but not for something deeper in the hierarchy) one needs to set the implementation class in a custom module's properties to be able to switch the implementation. Note also, that the objects created in DefaultSTKTemplateConfiguration are not taken into account at all. They're only used for merging the configurations which seems to be odd as well. I'd like to suggest using C2B for instantiating the merged template configuration (merge based on Content objects not beans). |
| Comments |
| Comment by Philipp Bärfuss [ 05/Nov/10 ] |
|
C2B is used to build the prototype object, so the class property can be used. The merging is a bit different than the extends mechanism as it merges the same template (Home for instances) with the current site. This allows to use the same templates with various site configurations. Note: to instantiate the bean we merge into, the more concrete object is uses as a reference, in that case this is the template definition. If you use a project specific main area in the prototype, then you have to configure that in the template as well. Otherwise the result will have the basic main area. protected Object mergeBean(List sources) { Object base = sources.get(0); Object instance; try { instance = base.getClass().newInstance(); } catch (Exception e) { log.error("Can't clone " + base, e); return base; } ... Don't hesitate to replay if you think I am wrong. |
| Comment by Vivian Steller [ 05/Nov/10 ] |
|
Understand. The "more concrete object" means the concrete template definition decides which implementation is used. STKTemplate mergedDef = (STKTemplate) BeanMergerUtil.merge(new Object[]{definition, site.getTemplates().getPrototype(), DefaultSTKTemplateConfiguration.getInstance()}); So, to override e.g. the header section you have two options: <properties>
<property>
<name>info.magnolia.module.templatingkit.templates.Header</name>
<value>ch.mway.magnolia.templates.Header</value>
</property>
</properties>
Second option: Set the class node data in your concrete templates, not the prototype. This is somehow not consistently following the idea behind the prototype inheritance but currently (due to the fact that beans are merged, not content objects) the way it is. Thanks Philipp! |