Templating in MidCOM
From OpenPSA Wiki
In addition to Midgard's templating mechanisms, the MidCOM Style Engine offers some more. The most important difference between regular Midgard and MidCOM is that Topics can be associated with Styles, which means that one can define a different style for each Topic instead of for all Topics accessed via a certain Page.
Note: This is not to be confused with MidCOM Site Template, which is a set of scripts to initialize a new MidCOM website.
Contents |
[edit] Loading Style Elements
MidCOM offers the possibility to load Style Elements. These must be referenced from either style-init or style-finish with the method midcom_show_style. With midcom_show_style, it is possible to load Style Elements from the entire Style tree, not just from the Style associated with the current Topic.
[edit] Component default Style Elements
MidCOM Components are shipped with a default set of Style Elements which are called at specific points under certain request URLs. These can be overwritten by creating a Style Element by the same name in the Style associated with the Topic in question. It is always a good idea to copy the default Style Element from the Component's directory and edit it afterwards, instead of writing one's own Style Elements from scratch.
[edit] Substyles
[edit] midcom-substyle
The Topic's Style can be overwritten with a Substyle. This can be done by explicitly naming a Substyle as a parameter for the MidCOM URL Method substyle. This URL method also works when used together with dynamic_load (except during the Content Output Phase.), enabling a Component to load content from another Component with a Style specific to this context.
Example
In /topic1, Style element element1 in Style style1 calls the request url /topic2/request_url in topic2 (associated with style2) and requests the Substyle substyle1:
$_MIDCOM->dynamic_load("midcom-substyle-substyle1/topic2/request_url");
This calls the Component associated with topic2 and the Style Element responsible for rendering request_url. Because of the use of midcom-substyle, MidCOM's Style Engine will look in /style2/substyle1, if nothing can be found there, it will look in /style2. If both of those don't contain the necessary Style Element, the Component default Style Element will be used.
[edit] Datamanager Schemas
In most MidCOM Components, if more than one MgdSchema is available, an implicit Substyle which is named like the Schema is available. For example, if a Topic topic_a has two Schemas, schema_b and schema_c, MidCOM will try to load the Style Elements from topic_a Style/schema_a or topic_a Style/schema_b respectively. If those are not available, topic_a Style is loaded instead.
[edit] Symlink Content Topic
While midcom-substyle and dynamic_load can be used to load an individual object into a different style, some Components also offer the possibility to create a completely separate "view" of a particular Topic by creating a Symlink Content Topic. This is a Topic which has its own Style but reuses data available under a different topic, thus allowing to create a completely separate Look and Feel while keeping all data centralized in one spot.
Symlink Content Topic is available in the following Components (incomplete):
see also Midgard Execution Phases
