I'm trying to import a js file as type module in CakePHP 2.10.22. You can do something like this
echo $this->Html->script('test', array('inline' => false, 'type' => 'module'));
but that results in the tag being like <script type="text/javascript" type="module">
I also tired
echo $this->Html->tag(
'script',
null,
array(
'type' => 'module',
'src' => '/test/js/objects/test.js'
)
);
But it does not put it inside of the head html tag.
Is there a way to add on or make a custom helper that will add it into the head?
When using the HTML helper, one option would be to customize the template that is used for generating the script tag, that is
javascriptlink, which by default has thetypeattribute hard coded:This would then require that you always specify a
typefor your script tags in case needed.Another option would be to generate custom tags as shown in your question, and use the view's
append()method to add it to the respective view block that renders in your layout, by default that would be the block namedscript:This could certainly be implemented in a custom/extended HTML helper if you wanted to.
See also