Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-13099

Extensions cannot add filters, extensions and context variables to twig

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Invalid
    • 3.1.0-RC4
    • 3.2.0-a1
    • Template Engine
    • None
    • PHP 5.5.10

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: