1010namespace Symfony \WebpackEncoreBundle \Twig ;
1111
1212use Psr \Container \ContainerInterface ;
13+ use Symfony \WebpackEncoreBundle \Asset \EntrypointLookup ;
1314use Symfony \WebpackEncoreBundle \Asset \EntrypointLookupInterface ;
1415use Symfony \WebpackEncoreBundle \Asset \TagRenderer ;
16+ use Symfony \WebpackEncoreBundle \Exception \EntrypointNotFoundException ;
1517use Twig \Extension \AbstractExtension ;
1618use Twig \TwigFunction ;
1719
@@ -31,6 +33,7 @@ public function getFunctions(): array
3133 new TwigFunction ('encore_entry_css_files ' , [$ this , 'getWebpackCssFiles ' ]),
3234 new TwigFunction ('encore_entry_script_tags ' , [$ this , 'renderWebpackScriptTags ' ], ['is_safe ' => ['html ' ]]),
3335 new TwigFunction ('encore_entry_link_tags ' , [$ this , 'renderWebpackLinkTags ' ], ['is_safe ' => ['html ' ]]),
36+ new TwigFunction ('encore_entry_exists ' , [$ this , 'entryExists ' ]),
3437 ];
3538 }
3639
@@ -58,6 +61,16 @@ public function renderWebpackLinkTags(string $entryName, string $packageName = n
5861 ->renderWebpackLinkTags ($ entryName , $ packageName , $ entrypointName , $ attributes );
5962 }
6063
64+ public function entryExists (string $ entryName , string $ entrypointName = '_default ' ): bool
65+ {
66+ $ entrypointLookup = $ this ->getEntrypointLookup ($ entrypointName );
67+ if (!$ entrypointLookup instanceof EntrypointLookup) {
68+ throw new \LogicException (sprintf ('Cannot use entryExists() unless the entrypoint lookup is an instance of "%s" ' , EntrypointLookup::class));
69+ }
70+
71+ return $ entrypointLookup ->entryExists ($ entryName );
72+ }
73+
6174 private function getEntrypointLookup (string $ entrypointName ): EntrypointLookupInterface
6275 {
6376 return $ this ->container ->get ('webpack_encore.entrypoint_lookup_collection ' )
0 commit comments