{
    "href": "/post/2015/03/23/using-aura-html-with-leagueplates/",
    "relId": "2015/03/23/using-aura-html-with-leagueplates",
    "title": "Using Aura.Html with League\\Plates",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/aura/",
            "relId": "aura",
            "title": "Aura",
            "author": null,
            "created": "2020-09-14 21:51:57 UTC",
            "updated": [
                "2020-09-14 21:51:57 UTC"
            ],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2015-03-23 17:37:22 UTC",
    "updated": [
        "2015-03-23 17:37:22 UTC"
    ],
    "html": "<p><a href=\"http://auraphp.com\">Aura</a> has its own native PHP template package, <a href=\"https://github.com/auraphp/Aura.View\">Aura.View</a>, a direct descendant of <a href=\"http://phpsavant.com\">Savant</a> and <a href=\"http://solarphp.com/apidoc/class.Solar_View.Overview\">Solar_View</a>, as well as a cousin to <a href=\"http://framework.zend.com/manual/current/en/modules/zend.view.quick-start.html\">Zend_View</a>.</p>\n<p>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 <a href=\"https://github.com/auraphp/Aura.Html\">Aura.Html</a> package.  This means the helpers can be used in any PHP presentation code, framework-based or otherwise.</p>\n<p>As an example, let\u2019s try integrating the helpers with <a href=\"http://platesphp.com\">Plates</a>, 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:</p>\n<pre><code class=\"php\">&lt;?php\n$plates = new League\\Plates\\Engine('/path/to/templates');\n$helper = (new Aura\\Html\\HelperLocatorFactory())-&gt;newInstance();\n\n$plates-&gt;registerFunction('anchor',     $helper-&gt;get('anchor'));\n$plates-&gt;registerFunction('anchorRaw',  $helper-&gt;get('anchorRaw'));\n$plates-&gt;registerFunction('base',       $helper-&gt;get('base'));\n$plates-&gt;registerFunction('form',       $helper-&gt;get('form'));\n$plates-&gt;registerFunction('img',        $helper-&gt;get('img'));\n$plates-&gt;registerFunction('input',      $helper-&gt;get('input'));\n$plates-&gt;registerFunction('label',      $helper-&gt;get('label'));\n$plates-&gt;registerFunction('links',      $helper-&gt;get('links'));\n$plates-&gt;registerFunction('metas',      $helper-&gt;get('metas'));\n$plates-&gt;registerFunction('ol',         $helper-&gt;get('ol'));\n$plates-&gt;registerFunction('scripts',    $helper-&gt;get('scripts'));\n$plates-&gt;registerFunction('styles',     $helper-&gt;get('styles'));\n$plates-&gt;registerFunction('tag',        $helper-&gt;get('tag'));\n$plates-&gt;registerFunction('title',      $helper-&gt;get('title'));\n$plates-&gt;registerFunction('ul',         $helper-&gt;get('ul'));\n?&gt;\n</code></pre>\n<p>Now you can use the <a href=\"https://github.com/auraphp/Aura.Html/blob/develop-2/README-HELPERS.md\">tag helpers</a> and <a href=\"https://github.com/auraphp/Aura.Html/blob/develop-2/README-FORMS.md\">form-building helpers</a> from Aura.Html in your Plates templates.  For example, if your Plates template looks like this \u2026</p>\n<pre><code class=\"html+php\">&lt;html&gt;\n&lt;head&gt;\n&lt;?= $this-&gt;title('My Title'); ?&gt;\n&lt;/head&gt;\n&lt;body&gt;\n&lt;p&gt;Try out &lt;?= $this-&gt;anchor(\n    'https://github.com/auraphp/Aura.Html',\n    'Aura.Html'\n); ?&gt;\nwith &lt;?= $this-&gt;anchor(\n    'http://platesphp.com',\n    'Plates'\n); ?&gt; !&lt;/p&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n<p>\u2026 it will render to:</p>\n<pre><code class=\"html\">&lt;html&gt;\n&lt;head&gt;\n    &lt;title&gt;My Title&lt;/title&gt;\n&lt;/head&gt;\n&lt;body&gt;\n&lt;p&gt;Try out &lt;a href=\"https://github.com/auraphp/Aura.Html\"&gt;Aura.Html&lt;/a&gt;\nwith &lt;a href=\"http://platesphp.com\"&gt;Plates&lt;/a&gt; !&lt;/p&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n<p>Try out <a href=\"https://github.com/auraphp/Aura.Html\">Aura.Html</a> today, and see how much you like it with your output system of choice. (We\u2019re partial to <a href=\"https://github.com/auraphp/Aura.View\">Aura.View</a> for that task, but then, we would be.)</p>\n<p><strong>UPDATE:</strong> As usual, Hari KT is ahead of the curve with his post on this same topic from a year ago: <a href=\"http://harikt.com/blog/2014/05/13/extending-plates-with-aura-html-helpers/\">http://harikt.com/blog/2014/05/13/extending-plates-with-aura-html-helpers/</a>.</p>\n<p><strong>UPDATE 2:</strong> Someone asked how easy it is to use Aura.Html with Aura.View. It's 3-lines-easy: see <a href=\"https://github.com/auraphp/Aura.View#custom-helper-managers\">https://github.com/auraphp/Aura.View#custom-helper-managers</a>.</p>\n<hr>\n<p class=\"reddit-links\">Read the Reddit discussion about this post <a href=\"https://www.reddit.com/r/PHP/comments/3017sc/using_aurahtml_with_leagueplates/\">here</a>.</p>\n"
}
