Skip to content

Commit

Permalink
Added new events and paths to support namespacing #1604
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Aug 11, 2017
1 parent 926d78d commit a37582e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
1. [](#new)
* Added a new `cache_control` system and page level property [#1591](https://github.com/getgrav/grav/issues/1591)
* Added a new `clear_images_by_default` system property to stop cache clear events from removing processed images [#1481](https://github.com/getgrav/grav/pull/1481)
* Added new `onTwigLoader()` event to enable utilization of loader methods
* Added new `Twig::addPath()` and `Twig::prependPath()` methods to wrap loader methods and support namespacing [#1604](https://github.com/getgrav/grav/issues/1604)
1. [](#bugfix)
* Allow `session.timetout` field to be set to `0` via blueprints [#1598](https://github.com/getgrav/grav/issues/1598)

Expand Down
23 changes: 23 additions & 0 deletions system/src/Grav/Common/Twig/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public function init()
$this->grav->fireEvent('onTwigTemplatePaths');

$this->loader = new \Twig_Loader_Filesystem($this->twig_paths);

$this->grav->fireEvent('onTwigLoader');

$this->loaderArray = new \Twig_Loader_Array([]);
$loader_chain = new \Twig_Loader_Chain([$this->loaderArray, $this->loader]);

Expand Down Expand Up @@ -359,6 +362,26 @@ public function processSite($format = null, array $vars = [])
return $output;
}

/**
* Wraps the Twig_Loader_Filesystem addPath method (should be used only in `onTwigLoader()` event
* @param $template_path
* @param null $namespace
*/
public function addPath($template_path, $namespace = null)
{
$this->loader->addPath($template_path, $namespace);
}

/**
* Wraps the Twig_Loader_Filesystem prependPath method (should be used only in `onTwigLoader()` event
* @param $template_path
* @param null $namespace
*/
public function prependPath($template_path, $namespace = null)
{
$this->loader->prependPath($template_path, $namespace);
}

/**
* Simple helper method to get the twig template if it has already been set, else return
* the one being passed in
Expand Down

0 comments on commit a37582e

Please sign in to comment.