Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-13099

Extensions cannot add filters, extensions and context variables to twig

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Major Major
    • 3.2.0-a1
    • 3.1.0-RC4
    • Template Engine
    • None
    • PHP 5.5.10

      Currently if you want to add a new twig filter or extension from your phpbb extension, you basically need to replace \phpbb\template\twig\twig with your own class.

      This is because of Twig environment will be locked inside the constructor after setting the lexer.

      Replacing the original class or service by your custom one causes a lot of issues
      1) you need to keep your class in sync with each phpbb version
      2) only one extension works at any time, making twig extensions incompatible with each other

      To fix this I propose adding the following events:

      The first event called something like "twig.extend" called inside the contructor before $this->twig->setLexer($lexer); This event needs to send $this->twig as the parameter.

      And the second event "twig.context" called inside get_template_vars() to allow extensions to inject extra context variables.

            nicofuma nicofuma
            hexplor hexplor [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: