10000 minor #18849 [Encore] webpack encore reset entrypointlookup (Gilles G… · symfony/symfony-docs@d539070 · GitHub
[go: up one dir, main page]

Skip to content

Commit d539070

Browse files
committed
minor #18849 [Encore] webpack encore reset entrypointlookup (Gilles Gauthier)
This PR was merged into the 5.4 branch. Discussion ---------- [Encore] webpack encore reset entrypointlookup With WebpackEncore, explain how to call reset when you have multiple render in the same request I'm not sure if the advance-config.rst is the right place, because it's related to Symfony 🤔 and webpack_encore `@weaverryan` Commits ------- ef78cf1 webpack encore reset entrypointlookup
2 parents 8c080f4 + ef78cf1 commit d539070

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

frontend/encore/advanced-config.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,65 @@ functions to specify which build to use:
144144
{{ encore_entry_script_tags('mobile', null, 'secondConfig') }}
145145
{{ encore_entry_link_tags('mobile', null, 'secondConfig') }}
146146
147+
Avoid missing CSS when render multiples html
148+
--------------------------------------------
149+
150+
When you need to generate two templates in the same request, such as two emails, you should call the reset method on
151+
the ``EntrypointLookupInterface`` interface.
152+
153+
To do this, inject the ``EntrypointLookupInterface`` interface
154+
155+
.. code-block:: php
156+
157+
public function __construct(EntrypointLookupInterface $entryPointLookup) {}
158+
159+
public function send() {
160+
$this->twig->render($emailOne);
161+
$this->entryPointLookup->reset();
162+
$this->render($emailTwo);
163+
}
164+
165+
If you are using multiple webpack configurations, for example, one for the admin and one for emails, you will need to
166+
inject the correct ``EntrypointLookupInterface`` service. To achieve this, you should search for the service
167+
using the following command:
168+
169+
.. code-block:: terminal
170+
171+
# if you are using symfony CLI
172+
$ symfony console debug:container entrypoint_lookup
173+
174+
# You will see a result similar to this:
175+
Select one of the following services to display its information:
176+
[0] webpack_encore.entrypoint_lookup_collection
177+
[1] webpack_encore.entrypoint_lookup.cache_warmer
178+
[2] webpack_encore.entrypoint_lookup[_default]
179+
[3] webpack_encore.entrypoint_lookup[admin]
180+
[4] webpack_encore.entrypoint_lookup[email]
181+
182+
The service we are interested in is ``webpack_encore.entrypoint_lookup[email]``.
183+
184+
To inject this service into your class, we will use the bind method:
185+
186+
.. code-block:: yaml
187+
188+
services:
189+
_defaults
190+
bind:
191+
Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface $entryPointLookupEmail: '@webpack_encore.entrypoint_lookup[email]'
192+
193+
194+
Now you can inject your service into your class:
195+
196+
.. code-block:: php
197+
198+
public function __construct(EntrypointLookupInterface $entryPointLookupEmail) {}
199+
200+
public function send() {
201+
$this->twig->render($emailOne);
202+
$this->entryPointLookupEmail->reset();
203+
$this->render($emailTwo);
204+
}
205+
147206
Generating a Webpack Configuration Object without using the Command-Line Interface
148207
----------------------------------------------------------------------------------
149208

0 commit comments

Comments
 (0)
0