Download the PHP package rodnaph/morgan without Composer
On this page you can find all versions of the php package rodnaph/morgan. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rodnaph/morgan
More information about rodnaph/morgan
Files in rodnaph/morgan
Package morgan
Short Description Pure HTML Templating for PHP
License MIT
Homepage https://github.com/rodnaph/morgan
Informations about the package morgan
Morgan - Pure HTML Templating for PHP 
Morgan is a small templating library for PHP to enable using 'pure HTML' templates. This means that no templating is included in your HTML files, they are meant to be fully standalone components that you can view and edit independently. Morgan then handles transforming these templates using your application data.
Morgan is a PHP port of the ideas from EnLive.
Usage
If you want to dive straight in there's an example application with more details.
Here, we're rendering a template using a HTML file we have. When we call render we pass the name of the source file, and an array of key/value pairs where the keys are CSS selectors to match elements in the document, and the values are functions to transform those elements.
So in the above example we're selecting all h1 elements inside .header elements, and then we're setting their content to the string 'Some Text'. T::render() will echo the content of the template, you can also use T::fetch() to just return the transformed content.
You can also get handles to Callable template functions like this...
Transformers
In the above simple example the transformer we used was the content transformer. There are other transformers available…
Custom Transformers
You can also create your own transformers, they are just functions which accept a DOMElement object and mutate it in some way.
Multi Transforms
Often you'll want to apply multiple transformers to a given selector. You can do this by using the all form.
Snippets
As well as entire documents, you can also create snippets. These are fragments of some document, and you can use them for things like extracting a blog post from a HTML file, then rendering this post in another template.
The second argument is the CSS selector for selecting the fragment from the document.
Less Trivial Example
As a more fully featured example, imagine you have a page where you want to list a bunch of blog posts. This page will contain a title, then a list of blog post subjects with a short summary of their content (the title linking to each post).
We can markup this in a single file called blog-posts.html, then use it as the template for our page, extract the example snippet for a blog post in summary view to use for the blog posts.
Object Orientated Usage
As well as the static interface you can also use Morgan in an OOP manner if you like.
Installation with Composer
Morgan is available via Composer, just require it and specify the version you want to use.
Motivation
This library was inspired by EnLive, and is mainly a just-for-fun implementation in PHP. If you find it useful though feel free to contribute!
TODO
The following functions from EnLive are not implemented yet, so I still need to review them and do that if they make sense...