Skip to content

Commit cd61a85

Browse files
committed
Add docs for HtmlHelper::importmap()
1 parent d3eec80 commit cd61a85

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

en/appendices/5-2-migration-guide.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Behavior Changes
1818
being filterable from logging.
1919
- ``NumericPaginator::paginate()`` now uses the ``finder`` option even when a ``SelectQuery`` instance is passed to it.
2020

21-
2221
Deprecations
2322
============
2423

@@ -87,7 +86,9 @@ View
8786
----
8887

8988
- ``FormHelper::deleteLink()`` has been added as convenience wrapper for delete links in
90-
templates using `DELETE` method.
89+
templates using ``DELETE`` method.
90+
- ``HtmlHelper::importmap()`` was added. This method allows you to define
91+
import maps for your JavaScript files.
9192

9293
Error
9394
-----

en/views/helpers/html.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,66 @@ Once you have buffered javascript, you can output it as you would any other
561561
// In your layout
562562
echo $this->fetch('script');
563563

564+
Creating Javascript Importmap
565+
-----------------------------
566+
567+
.. php:method:: importmap(array $map, array $options = []): string
568+
569+
Creates an `importmap` script tag for your JavaScript files::
570+
571+
// In the head tag of your layout
572+
echo $this->Html->importmap([
573+
'jquery' => 'jquery.js',
574+
'wysiwyg' => '/editor/wysiwyg.js'
575+
]);
576+
577+
Will output:
578+
579+
.. code-block:: html
580+
581+
<script type="importmap">{
582+
"imports": {
583+
"jquery": "/js/jquery.js",
584+
"wysiwyg": "/editor/wysiwyg.js"
585+
}
586+
}</script>
587+
588+
Generating maps with imports, scopes and integrity::
589+
590+
echo $this->Html->importmap([
591+
'imports' => [
592+
'jquery' => 'jquery-3.7.1.min.js',
593+
'wysiwyg' => '/editor/wysiwyg.js'
594+
],
595+
'scopes' => [
596+
'scoped/' => [
597+
'foo' => 'inner/foo',
598+
],
599+
],
600+
'integrity' => [
601+
'jquery' => 'sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=',
602+
],
603+
]);
604+
605+
Will output:
606+
607+
.. code-block:: html
608+
609+
<script type="importmap">{
610+
"imports": {
611+
"jquery": "/js/jquery-3.7.1.min.js",
612+
"wysiwyg": "/editor/wysiwyg.js"
613+
},
614+
"scopes": {
615+
"scoped/": {
616+
"foo": "/js/inner/foo.js"
617+
}
618+
},
619+
"integrity": {
620+
"/js/jquery-3.7.1.min.js": "sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
621+
}
622+
}</script>
623+
564624
Creating Nested Lists
565625
---------------------
566626

0 commit comments

Comments
 (0)