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 ;
16
+ use Symfony \WebpackEncoreBundle \Exception \EntrypointNotFoundException ;
15
17
use Twig \Extension \AbstractExtension ;
16
18
use Twig \TwigFunction ;
17
19
@@ -31,6 +33,7 @@ public function getFunctions(): array
31
33
new TwigFunction ('encore_entry_css_files ' , [$ this , 'getWebpackCssFiles ' ]),
32
34
new TwigFunction ('encore_entry_script_tags ' , [$ this , 'renderWebpackScriptTags ' ], ['is_safe ' => ['html ' ]]),
33
35
new TwigFunction ('encore_entry_link_tags ' , [$ this , 'renderWebpackLinkTags ' ], ['is_safe ' => ['html ' ]]),
36
+ new TwigFunction ('encore_entry_exists ' , [$ this , 'entryExists ' ]),
34
37
];
35
38
}
36
39
@@ -58,6 +61,16 @@ public function renderWebpackLinkTags(string $entryName, string $packageName = n
58
61
->renderWebpackLinkTags ($ entryName , $ packageName , $ entrypointName , $ attributes );
59
62
}
60
63
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
+
61
74
private function getEntrypointLookup (string $ entrypointName ): EntrypointLookupInterface
62
75
{
63
76
return $ this ->container ->get ('webpack_encore.entrypoint_lookup_collection ' )
0 commit comments