Checking the source code indicates that there is no way to implement such tag as it's obvious that the format of attributes is %s="%s"
.
If you really need this I think the easiest way now is to provide your own customized HtmlHelper
by extending the core HtmlHelper
, and overwrite the _formatAttribute
function:
Note: this is for CakePHP 1.3.x only and it's pretty messy as it can't specify className
in the helpers array. CakePHP 2.x provides a cleaner way to overwrite default core helper with ease, but it's not what OP wanted so I'll not put it up here
Create
app/views/helpers/custom_html.php
:<?php App::import('Helper', 'Html'); class CustomHtmlHelper extends HtmlHelper { function __formatAttribute($key, $value, $escape = true) { if (in_array($key, array('async', 'defer'))) { return $key; } return parent::__formatAttribute($key, $value, $escape); } }
In your
app_controller.php
or whatever main controller that need this, use theCustomHtmlHelper
by:var $helpers = array('CustomHtml');
And in your view, you can now start using
async
ordefer
tag. Feel free to extend this array if you see fit.echo $this->CustomHtml->script('test', array('async' => 'async'));