@@ -105,21 +105,53 @@ If you want more control, you can use the `encore_entry_js_files()` and
105105` encore_entry_css_files() ` methods to get the list of files needed, then
106106loop and create the ` script ` and ` link ` tags manually.
107107
108- ## Rendering Multiple Times in a Request (e.g. to Generate a PDF )
108+ ## Rendering Multiple Templates (e.g. Emails or PDFs )
109109
110110When you render your script or link tags, the bundle is smart enough
111111not to repeat the same JavaScript or CSS file within the same request.
112112This prevents you from having duplicate ` <link> ` or ` <script> ` tags
113- if you render multiple entries that both rely on the same file.
113+ if you render multiple entries that rely on the same file.
114114
115115In some cases, however, you may want to render the script & link
116- tags for the same entry multiple times in a request. For example,
117- if you render multiple Twig templates to create multiple PDF files
118- during a single request.
116+ tags for the same entry multiple times in a request - for example
117+ when rendering Twig templates for a PDF or for an email.
119118
120- In that case, before each render, you'll need to "reset" the internal
121- cache so that the bundle re-renders CSS or JS files that it previously
122- rendered. For example, in a controller:
119+ The easiest solution is to * disable* the "file tracking" on those
120+ templates:
121+
122+ ``` twig
123+ {# some template that renders a PDF or an email #}
124+
125+ {% do encore_disable_file_tracking() %}
126+ {{ encore_entry_link_tags('entry1') }}
127+ {{ encore_entry_script_tags('entry1') }}
128+ {% do encore_enable_file_tracking() %}
129+ ```
130+
131+ With this, * all* JS and CSS files for ` entry1 ` will be rendered and
132+ this won't affect any other Twig templates rendered in the request.
133+
134+ You can also use this along with ` inline_css ` and ` encore_entry_css_source() `
135+ to automatically convert the CSS to inline styles so that your emails
136+ or PDF doesn't require any external CSS files:
137+
138+ ``` twig
139+ {% do encore_disable_file_tracking() %}
140+ {% apply inline_css(encore_entry_css_source('my_entry')) %}
141+ <div>
142+ Hi! The CSS from my_entry will be converted into
143+ inline styles on any HTML elements inside.
144+ </div>
145+ {% endapply %}
146+ {% do encore_enable_file_tracking() %}
147+ ```
148+
149+ ## Resetting the Entrypoint
150+
151+ If using ` encore_disable_file_tracking() ` won't work for you for some
152+ reason, you can also "reset" EncoreBundle's internal cache so that the
153+ bundle re-renders CSS or JS files that it previously rendered. For
154+ example, in a controller:
123155
124156``` php
125157// src/Controller/SomeController.php
0 commit comments