TemplateExtension.php 914 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace TemplateBundle\Twig;
  3. use TemplateBundle\Services\TemplateService;
  4. class TemplateExtension extends \Twig_Extension
  5. {
  6. /**
  7. * @var TemplateService
  8. */
  9. private $templateService;
  10. /**
  11. * @param TemplateService $templateService
  12. */
  13. public function __construct(TemplateService $templateService)
  14. {
  15. $this->templateService = $templateService;
  16. }
  17. /**
  18. * @return array
  19. */
  20. public function getFunctions()
  21. {
  22. return array(
  23. new \Twig_SimpleFunction('template_exists', array($this, 'templateExists')),
  24. );
  25. }
  26. /**
  27. * @param string $name
  28. *
  29. * @return boolean
  30. */
  31. public function templateExists($name)
  32. {
  33. return $this->templateService->exists($name);
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function getName()
  39. {
  40. return 'template_extension';
  41. }
  42. }