Skip to content

Commit

Permalink
Merge pull request #20 from bedita/feat/configurable-environment-for-…
Browse files Browse the repository at this point in the history
…twig

Setup Twig environment via configuration
  • Loading branch information
batopa authored May 19, 2020
2 parents 4ffa37f + 5c54e29 commit cc6c53d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/View/TwigView.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@
namespace BEdita\WebTools\View;

use BEdita\WebTools\View\Twig\BeditaTwigExtension;
use Cake\Core\Configure;
use Cake\TwigView\View\TwigView as BaseTwigView;

/**
* View class that uses TwigView and adds Twig extensions
*/
class TwigView extends BaseTwigView
{
/**
* {@inheritDoc}
*/
public function initialize(): void
{
$environment = (array)Configure::read('Twig.environment', []) + ['strict_variables' => false];
$this->setConfig('environment', $environment);

parent::initialize();
}

/**
* {@inheritDoc}
*/
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/View/TwigViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public function testInitialize(): void
$extensions = $View->getTwig()->getExtensions();
static::assertNotEmpty($extensions);
static::assertArrayHasKey('BEdita\WebTools\View\Twig\BeditaTwigExtension', $extensions);
static::assertFalse($View->getConfig('environment.strict_variables'));
}
}

0 comments on commit cc6c53d

Please sign in to comment.