@@ -14,32 +14,53 @@ a new ``checkout`` entry:
14
14
15
15
Encore
16
16
// an existing entry
17
- .addEntry('app', './assets/js/main.js')
18
- // a global styles entry
19
- .addStyleEntry('global', './assets/css/global.scss')
17
+ .addEntry('app', './assets/js/app.js')
20
18
21
19
+ .addEntry('checkout', './assets/js/checkout.js')
22
20
;
23
21
24
22
Inside ``checkout.js ``, add or require the JavaScript and CSS you need. Then, just
25
- include a ``script `` tag for ``checkout.js `` on the checkout page (and a ``link ``
26
- tag for ``checkout.css `` if you import any CSS).
23
+ call the ``encore_entry_link_tags() `` and ``encore_entry_script_tags() `` functions
24
+ *only * on the checkout page to include the new ``script `` and ``link `` tags
25
+ (if any ``link `` tag is needed):
26
+
27
+ .. code-block :: twig
28
+
29
+ {# templates/order/checkout.html.twig #}
30
+ {# ... #}
31
+
32
+ {#
33
+ Assuming you're using Symfony's standard base.html.twig setup, add
34
+ to the stylesheets and javascript blocks
35
+ #}
36
+
37
+ {% block javascripts %}
38
+ {{ parent() }}
39
+
40
+ {{ encore_entry_script_tags('checkout') }}
41
+ {% endblock %}
42
+
43
+ {% block stylesheets %}
44
+ {{ parent() }}
45
+
46
+ {{ encore_entry_link_tags('checkout') }}
47
+ {% endblock %}
27
48
28
49
Multiple Entries Per Page?
29
50
--------------------------
30
51
31
- Typically, you should include only *one * JavaScript entry per page. This means
32
- the checkout page will include ``checkout.js ``, but will *not * include the
33
- ``app.js `` that's used on the other pages. Think of the checkout page as its
34
- own "app", where ``checkout.js `` includes all the functionality you need.
52
+ Typically, you should include only *one * JavaScript entry per page. Think of the
53
+ checkout page as its own "app", where ``checkout.js `` includes all the functionality
54
+ you need.
35
55
36
- However, if there is some global JavaScript that you want included on *every *
37
- page, you *can * create an entry that contains that code and include both that
38
- entry *and * your page-specific entry. For example, suppose that the ``app ``
39
- entry above contains JavaScript you want on every page. In that case, include
40
- both ``app.js `` and ``checkout.js `` on the checkout page.
56
+ However, it's pretty common to need to include some global JavaScript and CSS on
57
+ every page. For that reason, it usually makes sense to have one entry (e.g. ``app ``)
58
+ that contains this global code and is included on every page (i.e. it's included
59
+ in the *layout * of your app). This means that you will always have one, global entry
60
+ on every page (e.g. ``app ``) and you *may * have one page-specific JavaScript and
61
+ CSS file from a page-specific entry (e.g. ``checkout ``).
41
62
42
63
.. tip ::
43
64
44
- Be sure to create a :doc: `shared entry </frontend/encore/shared-entry >` to avoid duplicating
45
- the Webpack bootstrap logic and any shared modules .
65
+ Be sure to use split chunks :doc: `shared entry </frontend/encore/split-chunks >`
66
+ to avoid duplicating and shared code between your entry files .
0 commit comments