Helpers.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Symfony\Framework\TwigBundle\Extension;
  3. use Symfony\Components\Templating\Engine;
  4. use Symfony\Framework\TwigBundle\TokenParser\HelperTokenParser;
  5. /*
  6. * This file is part of the Symfony package.
  7. *
  8. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9. *
  10. * For the full copyright and license information, please view the LICENSE
  11. * file that was distributed with this source code.
  12. */
  13. /**
  14. *
  15. * @package Symfony
  16. * @subpackage Framework_TwigBundle
  17. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  18. */
  19. class Helpers extends \Twig_Extension
  20. {
  21. /**
  22. * Returns the token parser instance to add to the existing list.
  23. *
  24. * @return array An array of Twig_TokenParser instances
  25. */
  26. public function getTokenParsers()
  27. {
  28. return array(
  29. // {% javascript 'bundles/blog/js/blog.js' %}
  30. new HelperTokenParser('javascript', '<js> [with <arguments:array>]', 'javascripts', 'add'),
  31. // {% javascripts %}
  32. new HelperTokenParser('javascripts', '', 'javascripts', 'render'),
  33. // {% stylesheet 'bundles/blog/css/blog.css' with ['media': 'screen'] %}
  34. new HelperTokenParser('stylesheet', '<css> [with <arguments:array>]', 'stylesheets', 'add'),
  35. // {% stylesheets %}
  36. new HelperTokenParser('stylesheets', '', 'stylesheets', 'render'),
  37. // {% route 'blog_post' with ['id': post.id] %}
  38. new HelperTokenParser('route', '<route> [with <arguments:array>]', 'router', 'generate'),
  39. // {% render 'BlogBundle:Post:list' with ['path': ['limit': 2], 'alt': 'BlogBundle:Post:error'] %}
  40. new HelperTokenParser('render', '<template> [with <arguments:array>]', 'actions', 'render'),
  41. );
  42. }
  43. /**
  44. * Returns the name of the extension.
  45. *
  46. * @return string The extension name
  47. */
  48. public function getName()
  49. {
  50. return 'symfony.helpers';
  51. }
  52. }