Aura has its own native PHP template package, Aura.View, a direct descendant of Savant and Solar_View, as well as a cousin to Zend_View.
The v1 Aura.View package used to include a helper system. Once we realized that there was no reason to tie the helper system directly to the view system, we released the helpers as a standalone Aura.Html package. This means the helpers can be used in any PHP presentation code, framework-based or otherwise.
As an example, let’s try integrating the helpers with Plates, a relative newcomer in the native PHP templating world. Plates allows you to register functions with its template engine, which means we can pull individual helpers out of Aura.Html and drop them into Plates, like so:
<?php
$plates = new League\Plates\Engine('/path/to/templates');
$helper = (new Aura\Html\HelperLocatorFactory())->newInstance();
$plates->registerFunction('anchor', $helper->get('anchor'));
$plates->registerFunction('anchorRaw', $helper->get('anchorRaw'));
$plates->registerFunction('base', $helper->get('base'));
$plates->registerFunction('form', $helper->get('form'));
$plates->registerFunction('img', $helper->get('img'));
$plates->registerFunction('input', $helper->get('input'));
$plates->registerFunction('label', $helper->get('label'));
$plates->registerFunction('links', $helper->get('links'));
$plates->registerFunction('metas', $helper->get('metas'));
$plates->registerFunction('ol', $helper->get('ol'));
$plates->registerFunction('scripts', $helper->get('scripts'));
$plates->registerFunction('styles', $helper->get('styles'));
$plates->registerFunction('tag', $helper->get('tag'));
$plates->registerFunction('title', $helper->get('title'));
$plates->registerFunction('ul', $helper->get('ul'));
?>
Now you can use the tag helpers and form-building helpers from Aura.Html in your Plates templates. For example, if your Plates template looks like this …
<html>
<head>
<?= $this->title('My Title'); ?>
</head>
<body>
<p>Try out <?= $this->anchor(
'https://github.com/auraphp/Aura.Html',
'Aura.Html'
); ?>
with <?= $this->anchor(
'http://platesphp.com',
'Plates'
); ?> !</p>
</body>
</html>
… it will render to:
<html>
<head>
<title>My Title</title>
</head>
<body>
<p>Try out <a href="https://github.com/auraphp/Aura.Html">Aura.Html</a>
with <a href="http://platesphp.com">Plates</a> !</p>
</body>
</html>
Try out Aura.Html today, and see how much you like it with your output system of choice. (We’re partial to Aura.View for that task, but then, we would be.)
UPDATE: As usual, Hari KT is ahead of the curve with his post on this same topic from a year ago: http://harikt.com/blog/2014/05/13/extending-plates-with-aura-html-helpers/.
UPDATE 2: Someone asked how easy it is to use Aura.Html with Aura.View. It’s 3-lines-easy: see https://github.com/auraphp/Aura.View#custom-helper-managers.
Read the Reddit discussion about this post here.
Good work Paul.
I did blogged regarding the same. I used a different technique and it was for version 2. Not sure how it works currently than from earlier versions.
In case if someone like to check http://harikt.com/blog/2014/05/13/extending-plates-with-aura-html-helpers/ . Not keeping the link to get any hits. Just for those who love to check a different variation.
[…] The v1 Aura.View package used to include a helper system. Once we realized that there was no reason to tie the helper system …read more […]
Why use PHP to render HTML tags?
Among other things, proper escaping in the proper locations.
One of the good thing is when it comes to Form. You created the form. Now you don’t need to repeat the name, and properties on the HTML also.
If you need to change the name, easy to change at one place. Hope that helps!
I’d be interested to see a comparison between Aura.View and Plates. Given their provenance I’d expect both to be of high quality, but how to choose between them…?
There are no practical, technical differences between them that I’m aware of. (I expect Jonathan Reinink will pipe up with a different assessment if he has one. 😉
You could choose based on non-technical reasons, such as liking the API or approach of one over the other. Aura.View is the more mature one, so if you really support the idea of reusing existing code, I assert there’s an ideological reason to side with Aura.View, but that’s a non-technical reason too.
Oh, nice. I’ll try to implement Aura.Html in Foil http://giuseppe-mazzapica.github.io/Foil/