1212use Psr \Container \ContainerInterface ;
1313use Symfony \WebpackEncoreBundle \Asset \EntrypointLookupInterface ;
1414use Symfony \WebpackEncoreBundle \Asset \TagRenderer ;
15+ use Symfony \WebpackEncoreBundle \Exception \EntrypointNotFoundException ;
1516use Twig \Extension \AbstractExtension ;
1617use Twig \TwigFunction ;
1718
@@ -29,6 +30,8 @@ public function getFunctions(): array
2930 return [
3031 new TwigFunction ('encore_entry_js_files ' , [$ this , 'getWebpackJsFiles ' ]),
3132 new TwigFunction ('encore_entry_css_files ' , [$ this , 'getWebpackCssFiles ' ]),
33+ new TwigFunction ('encore_has_entry_js_files ' , [$ this , 'hasWebpackJsFiles ' ]),
34+ new TwigFunction ('encore_has_entry_css_files ' , [$ this , 'hasWebpackCssFiles ' ]),
3235 new TwigFunction ('encore_entry_script_tags ' , [$ this , 'renderWebpackScriptTags ' ], ['is_safe ' => ['html ' ]]),
3336 new TwigFunction ('encore_entry_link_tags ' , [$ this , 'renderWebpackLinkTags ' ], ['is_safe ' => ['html ' ]]),
3437 ];
@@ -46,6 +49,30 @@ public function getWebpackCssFiles(string $entryName, string $entrypointName = '
4649 ->getCssFiles ($ entryName );
4750 }
4851
52+ public function hasWebpackJsFiles (string $ entryName , string $ entrypointName = '_default ' ): bool
53+ {
54+ try {
55+ $ entrypointLookup = $ this ->getEntrypointLookup ($ entrypointName );
56+ $ entrypointLookup ->reset ();
57+
58+ return count ($ entrypointLookup ->getJavaScriptFiles ($ entryName )) > 0 ;
59+ } catch (EntrypointNotFoundException $ e ) {
60+ return false ;
61+ }
62+ }
63+
64+ public function hasWebpackCssFiles (string $ entryName , string $ entrypointName = '_default ' ): bool
65+ {
66+ try {
67+ $ entrypointLookup = $ this ->getEntrypointLookup ($ entrypointName );
68+ $ entrypointLookup ->reset ();
69+
70+ return count ($ entrypointLookup ->getCssFiles ($ entryName )) > 0 ;
71+ } catch (EntrypointNotFoundException $ e ) {
72+ return false ;
73+ }
74+ }
75+
4976 public function renderWebpackScriptTags (string $ entryName , string $ packageName = null , string $ entrypointName = '_default ' , array $ attributes = []): string
5077 {
5178 return $ this ->getTagRenderer ()
0 commit comments