=======, (*1)
Molajito Render Package
, (*2)
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., (*3)
Sample
A working example of a website that has a
Home,
Blog,
Post,
Contact,
About,
page is available within this package. To view the sample,
configure an Apache Host to this
Sample / Public folder and
access the Host using your browser., (*4)
Basic Process:
Molajito initiates the rendering process by including
a Theme file as rendered output. The theme
contains
Include Statements discovered by Molajito
during parsing and used to identify what view
is to be rendered at that location., (*5)
Molajito uses three different types of `views':, (*6)
-
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., (*7)
-
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., (*8)
-
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 <article>
, <footer>
, or <header>
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., (*9)
You can also use include statements
to define
positions 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., (*10)
Theme
Themes are the first rendered output and therefore drive the rendering process. Typically, a
theme
defines necessary CSS and JS statements., (*11)
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., (*12)
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
., (*13)
In the theme
below, you will find include statements
for page
, template
and wrap
views., (*14)
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title><?= $this->runtime_data->site_title ?></title>
<link rel="stylesheet" href="/css/custom.css"/>
</head>
<body>
{I template=Navbar wrap=Nav I}
{I Breadcrumbs I}
{I page== $this->runtime_data->page_name ?> I}
{I Footer wrap=Nav I}
</body>
</html>
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
and easy to maintain. Molajito continues parsing rendered output after rendering each view until
no more include statements
are found., (*15)
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., (*16)
Extra attributes {I template=Templatename class=current,error dog=food I}
can be added to
the include statement
by adding named pair attributes., (*17)
Page
{I page=<? $this->runtime_data->page_name ?> 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., (*18)
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.', (*19)
{I template=Post I}
{I template=Comments I}
{I template=Paging I}
{I Sidebar I}
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
., (*20)
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., (*21)
$this->plugin_data->render->extension->$type->parameters->positions
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., (*22)
There are two ways to configure a template view
., (*23)
-
Custom.php - Molajito will inject the view
with $this->query_results
and this->runtime_data
,
but the view must handle looping, if needed., (*24)
-
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., (*25)
An example of a typical template view
Body.php file follows., (*26)
row->video) && $this->row->video !== '') { ?>
{I template=video link=<?= $this->row->video ?> I}
= $this->row->content; ?>
Wrap
{I template=Templatename wrap=Wrapname I}
To wrap a template view
, add the wrap=Wrapname
element to the include statement
., (*27)
A typical Wrap view
requires three files each of which Molajito will inject the view
with
$this->row
(containing the rendered output from the template view
) and this->runtime_data
., (*28)
<footer class="<?= $class ?>">
echo $this->row->content;
</footer>
Localization
{T Translate this string T}
Molajito supports localization using language strings and translations. Simply create a
token
like this example and inject the translate class [with an array of language strings and translations]
(https://github.com/Molajo/Molajito/blob/master/Sample/Bootstrap/Index.php#L20) or add an Translate Adapter for your
Translation class., (*29)
Requirements and Compliance
- PHP application framework independent, no dependencies
- Requires PHP 5.4, or above
- Uses Semantic Versioning
- Compliant with:
- [phpDocumentor2] (https://github.com/phpDocumentor/phpDocumentor2)
- [phpUnit Testing] (https://github.com/sebastianbergmann/phpunit)
- Author AmyStephen
- [Travis Continuous Improvement] (https://travis-ci.org/Molajo/Molajito)
- Listed on [Packagist] (https://packagist.org/packages/molajo/molajito) and installable using [Composer] (http://getcomposer.org/)
- Please use github to submit pull requests and features
- Licensed under the MIT License - see the
LICENSE
file for details