Working with Mosaik and Pieces

Mosaik module allows you to create pages or blocks using template files for layout and pieces of content.

The main target of Mosaik is to be, in its complexity, an easy to use module.
Everything you will use while developing/building your mosaiks is something that you'll already be familiar with (layout generation, pieces management, mosaik and pieces definitions).

In fact, what we believe is that a developer, or at least an expert Drupal user, already has all the necessary knowledge to use this set of modules.
If you've already implemented the hook_menu or hook_theme in your modules, or you've already managed the blocks placement into the various regions of your theme, you will realize to already know the concepts underlying Mosaik.

A Mosaik consists in a substructure of regions whose presentation is managed via a layout. Each layout is defined by a specific hook and its HTML code is located into a template file.
Mosaik layout regions can be filled with standard Drupal Blocks or with the most advanced Mosaik Pieces (you know this concept is really similar to the theme regions and blocks).
So, the short story is that a Mosaik is an aggregation of blocks and/or pieces displayed through a layout.

While Mosaiks and Pieces can be generated both via code and web UI, layouts can only be generated via code: this is a basic principle of Mosaik philosophy, because we hate the idea that HTML code can be stored into a Database table or managed via UI. Let do this work to those who know how to do it: themers / frontend developers.

A Mosaik is not a Drupal Entity, because we wanted to allow even beginner developers to be able to generate code based mosaiks in an easy way. So a Mosaik is more similar to a Menu item, but we will see it later.

Mosaik can be used for many scopes:

  • Creating your Home page (a real drama; each time a different approach; no more page-front.tpl.php; no more theme regions used only for the front page; finally a configurable home page where the blocks disposition can be changed without contexts and theme regions but via a specific layout and its regions, without affecting other pages configurations).
  • Creating single pages websites (you see those with horizontal sections with infinite scrolls and othre stuffs).
  • Creating Organic Groups predefined layouts and structures, with default blocks and styles etc.
  • Creating blocks collections (not just a list of blocks, but a Mosaik block which use a layout with regions filled with other blocks! Fantastic.)
  • Creating administrative pages with complex layouts.
  • Referencing existing mosaiks or pieces into your entities (node, taxonomy, user etc) just by using a field (so imagine you could reference a views that shows latest comments and latest articles into your Article content type.)
  • Drastic less usage of Context! (Remember that when you use Context, each rule is eavaluated for each page in order to load all necessary blocks - for example. So if you have 10 rules, Context will check for all of them each time. With Mosaik you have a direct access to the page structure and there's no need to eavluate anything).
  • your idea goes here

These are the basic info to start understanding what Mosaik really is and what and how it does its work.

Installation

Mosaik requires two contrib modules: Safeword and Views.
As any other Drupal 7 modules, from the modules management page, just enable Mosaik and Pieces modules.

install

Creating a Mosaik via code

You can generate your Mosaiks also implementing hook_mosaik() from your module:

Creating a Piece via code

To define a piece you have to implement hook_mosaik_piece() (the following code is taken directly from piece module):

Defining a Mosaik layout

Mosaik Layouts definition is as simple as hook_theme implementation.

Extending / altering default piece callback types

If your are a developer and you want to add or alter the default piece callback types, you can do it implementing hook_pieces_callbacks

Mosaik Management

You can access Mosaik administration section from the admin/structure/mosaik page.

Mosaik and Features

Mosaiks and pieces are exportable via the contrib module Features.

Mosaik internationalization

If you are working on a multilanguage website, and you want to use Mosaik, you'll surely need to enable i18n_mosaik.

Pieces Management

You can access Pieces administration section from the admin/structure/mosaik/pieces page.

Referencing Mosaiks and Pieces

mosaik_reference and pieces_reference submodules provide two new field types for referencing mosaik and pieces. They are really similar

Guide maintainers

aronne's picture