10
10
namespace Symfony \WebpackEncoreBundle \Twig ;
11
11
12
12
use Psr \Container \ContainerInterface ;
13
+ use Symfony \WebpackEncoreBundle \Asset \EntrypointLookup ;
13
14
use Symfony \WebpackEncoreBundle \Asset \EntrypointLookupInterface ;
14
15
use Symfony \WebpackEncoreBundle \Asset \TagRenderer ;
15
16
use Twig \Extension \AbstractExtension ;
@@ -31,6 +32,7 @@ public function getFunctions(): array
31
32
new TwigFunction ('encore_entry_css_files ' , [$ this , 'getWebpackCssFiles ' ]),
32
33
new TwigFunction ('encore_entry_script_tags ' , [$ this , 'renderWebpackScriptTags ' ], ['is_safe ' => ['html ' ]]),
33
34
new TwigFunction ('encore_entry_link_tags ' , [$ this , 'renderWebpackLinkTags ' ], ['is_safe ' => ['html ' ]]),
35
+ new TwigFunction ('encore_entry_exists ' , [$ this , 'entryExists ' ]),
34
36
];
35
37
}
36
38
@@ -58,6 +60,16 @@ public function renderWebpackLinkTags(string $entryName, string $packageName = n
58
60
->renderWebpackLinkTags ($ entryName , $ packageName , $ entrypointName , $ attributes );
59
61
}
60
62
63
+ public function entryExists (string $ entryName , string $ entrypointName = '_default ' ): bool
64
+ {
65
+ $ entrypointLookup = $ this ->getEntrypointLookup ($ entrypointName );
66
+ if (!$ entrypointLookup instanceof EntrypointLookup) {
67
+ throw new \LogicException (sprintf ('Cannot use entryExists() unless the entrypoint lookup is an instance of "%s" ' , EntrypointLookup::class));
68
+ }
69
+
70
+ return $ entrypointLookup ->entryExists ($ entryName );
71
+ }
72
+
61
73
private function getEntrypointLookup (string $ entrypointName ): EntrypointLookupInterface
62
74
{
63
75
return $ this ->container ->get ('webpack_encore.entrypoint_lookup_collection ' )
0 commit comments