Page styling and Datamanager schemas

Most Midgard components use a tool called Datamanager to abstract data storage and content editing. With Datamanager, site builders can define multiple schemas to be used at different areas or for different page types, each with a different set of content and editing fields.

With some recent commits coming to the next MidCOM 2.6 beta, Datamanager schemas can also be used for controlling the site layout. Each schema can have its own name, and this can be used for two things:

Defining page types

Schema can be chosen either on page creation, or with slight modifications, when editing the page. You can have multiple schemas available in same folder, each of them with a unique schema name.

With the new Metadata Service in MidCOM 2.6, the schema name is now available through an API, which means you can easily set the class of the HTML body element or some div with it:

<body class="<?php echo $_MIDCOM->metadata->get_page_class(); ?>">

After this changing layouts per schema is a simple CSS exercise.

Changing style templates

In addition to changing HTML classes used for CSS purposes, schema names can also be used automatically in defining which MidCOM style templates to use for the component’s output.

When a component registers its Datamanager schema name to MidCOM, the name will also be automatically appended into the style path used (unless it is default).

This means that if my site uses style called /bergie-2006, and I create a page with schema blogentry, MidCOM will automatically look if a style with path /bergie-2006/blogentry exists and use that instead of the default style for displaying component output elements like <(feeds)> and <(archive-list-start)>.

Registering the schema name

Registering the name of schema used by component is optional, and so far only the three most common CMS components: net.nehmer.static, and net.nemein.calendar utilize it. I’ll try to get support for this into most of the components soon, though, as it is a simple one-liner to register this information with the metadata service:

$_MIDCOM->bind_view_to_object($this->_article, $this->_datamanager->schema->name);

(this example is from net.nehmer.static view handler class)

Read more Midgard posts.