PHPackages                             molajo/molajito - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. molajo/molajito

ActiveMolajo-package[Templating &amp; Views](/categories/templating)

molajo/molajito
===============

Molajito View Rendering for PHP Applications

0.1.0(12y ago)53211MITPHPPHP &gt;=5.4

Since Feb 1Pushed 10y ago4 watchersCompare

[ Source](https://github.com/Molajo/Molajito)[ Packagist](https://packagist.org/packages/molajo/molajito)[ Docs](http://github.com/Molajo/Molajito)[ RSS](/packages/molajo-molajito/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

======= Molajito Render Package
===============================

[](#molajito-render-package)

[![Build Status](https://camo.githubusercontent.com/283417ff7ecda0e830d2d6ef3ae53a0254fb56740b0644cf2274e2c51e36e580/68747470733a2f2f7472617669732d63692e6f72672f4d6f6c616a6f2f4d6f6c616a69746f2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Molajo/Molajito)

Molajito is a template environment for frontend developers who want to focus on markup, not programming. It locates views, injects escaped data, integrates with Event handling, offers translation support for language strings, and more.

Sample
------

[](#sample)

A working example of a website that has a [Home](https://raw.githubusercontent.com/Molajo/Molajito/master/Sample/Screenshots/Home.png), [Blog](https://raw.githubusercontent.com/Molajo/Molajito/master/Sample/Screenshots/Blog.png), [Post](https://raw.githubusercontent.com/Molajo/Molajito/master/Sample/Screenshots/Post.png), [Contact](https://raw.githubusercontent.com/Molajo/Molajito/master/Sample/Screenshots/Contact.png), [About](https://raw.githubusercontent.com/Molajo/Molajito/master/Sample/Screenshots/About.png), page is available within this package. To view the sample, configure an Apache Host to this [ Sample / Public ](https://github.com/Molajo/Molajito/tree/master/Sample/Public) folder and access the Host using your browser.

Basic Process:
--------------

[](#basic-process)

Molajito initiates the rendering process by including a [Theme](https://github.com/Molajo/Molajito#theme) file as rendered output. The `theme` contains [Include Statements](https://github.com/Molajo/Molajito#include-statements) discovered by Molajito during parsing and used to identify what `view` is to be rendered at that location.

Molajito uses three different types of `views':

- [Page](https://github.com/Molajo/Molajito#page) views define layouts. A site typically has different layouts and the page view is useful for that purpose. Molajito does not pass data into the `page view`, it only includes the `page view` file.
- [Template](https://github.com/Molajo/Molajito#template) views define one specific area of the page, for example a `template view` could render a navigation menu, a blog post, or an author profile. Molajito passes in data to the `template view` in support of the rendering process.
- [Wrap](https://github.com/Molajo/Molajito#wrap) views *wrap* the rendered output from a `template view` in a specific manner. For example, a wrap might enclose the template output in an ``, ``, or `` content-specific HTML5 element. A wrap might also be used to achieve a certain visual effect for the content, for example by including a message in a div with an `alert` class.

You can also use `include statements` to define [positions](https://github.com/Molajo/Molajito#position) which are placeholders that can be associated with one or more `template views`. For example, you might want a `sidebar position`for a blog that can be configured by site builders.

### Theme

[](#theme)

Themes are the first rendered output and therefore drive the rendering process. Typically, a `theme` defines necessary CSS and JS statements.

Molajito injects a data object called `$this->runtime_data` into the Theme. As can be seen in the following example, Molajito passes in the `$this->runtime_data->page_name`value used in the page include statement.

You can add data the `$this->runtime_data` so that the data are available for rendering. In this example, `site_name` is used to render `title`.

In the `theme` below, you will find `include statements` for `page`, `template` and `wrap` views.

```

    runtime_data->site_title ?>

    {I template=Navbar wrap=Nav I}
    {I Breadcrumbs I}
    {I page=runtime_data->page_name ?> I}

    {I Footer wrap=Nav I}

```

### Include Statements

[](#include-statements)

Molajito uses `include statements` to define where specific views should be rendered. `Include statements` can be defined within any `theme` or `template` which helps to create reusable templates referenced in many places in order to keep your views [DRY](http://en.wikipedia.org/wiki/Don%27t_repeat_yourself)and easy to maintain. Molajito continues parsing rendered output after rendering each view until no more `include statements` are found.

The Include syntax is simple `{I type=Name I}`:

- `{I` marks the start of an include statement;
- `type=` set to `template` or `page`; If omitted, Molajito first assumes it is a `position`, and then looks for a like-named `template`;
- `Name` identifies the view associated with the type specified;
- `I}` marks the end of an include statement.

Extra attributes `{I template=Templatename class=current,error dog=food I}` can be added to the `include statement` by adding named pair attributes.

### Page

[](#page)

```
{I page= I}

```

`Themes` are typically where `page views` are defined. The `page_name` is passed into the `theme` via the `$this->runtime_data->page_name` object. However, a `page view` could be defined anywhere. What is important to remember is that Molajito simple includes the `page view` file without passing in data.

Following is an example of a `page view` for a blog post. The page layout calls for three `template views`: a post, comments, and a paging template. The page layout also includes a `sidebar` position. If there is no position with the name `sidebar`, Molajito searches for a like-named `template view.'

```

        {I template=Post I}
        {I template=Comments I}
        {I template=Paging I}

        {I Sidebar I}

```

### Position

[](#position)

```
{I Sidebar I}

```

If `type=` is omitted from the `include statement`, Molajito first searches for a `position`with that name. If a `position` with that name is not found, Molajito next search for a like named `template view`.

You can define which `template views` are associated with a position by defining the values in an array for $type = 'page' or $type = 'theme'. Molajo will check for positions in that sequence. If positions are found, Molajito inserts `(I template=Name I}` values for each `template view` defined.

```
$this->plugin_data->render->extension->$type->parameters->positions

```

### Template

[](#template)

```
{I template=Templatename I}

```

Molajito injects data into the `Template view` for support in rendering. As with the `Theme`, Molajito passes in the `$this->runtime_data` object which you can use to ensure specific data is available for rendering.

There are two ways to configure a `template view`.

1. Custom.php - Molajito will inject the `view` with `$this->query_results` and `this->runtime_data`, but the view must handle looping, if needed.
2. Header.php, Body.php, and Footer.php - Molajito will inject `Body.php` with `$this->row` and `$this->runtime_data` one time for each row. If `Header.php` exists, it will get the first row. If `Footer.php` exists, it will get the last row.

An example of a typical `template view` Body.php file follows.

```
