|
@@ -0,0 +1,52 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace TemplateBundle\Twig;
|
|
|
+
|
|
|
+use TemplateBundle\Services\TemplateService;
|
|
|
+
|
|
|
+class TemplateExtension extends \Twig_Extension
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var TemplateService
|
|
|
+ */
|
|
|
+ private $templateService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param TemplateService $templateService
|
|
|
+ */
|
|
|
+ public function __construct(TemplateService $templateService)
|
|
|
+ {
|
|
|
+ $this->templateService = $templateService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getFunctions()
|
|
|
+ {
|
|
|
+ return array(
|
|
|
+ new \Twig_SimpleFunction('template_exists', array($this, 'templateExists')),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $name
|
|
|
+ *
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ public function templateExists($name)
|
|
|
+ {
|
|
|
+ return $this->templateService->exists($name);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getName()
|
|
|
+ {
|
|
|
+ return 'template_extension';
|
|
|
+ }
|
|
|
+
|
|
|
+}
|