Skip to content

Instantly share code, notes, and snippets.

@Nicofuma
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicofuma/6d5c40265a631bd09882 to your computer and use it in GitHub Desktop.
Save Nicofuma/6d5c40265a631bd09882 to your computer and use it in GitHub Desktop.
<?php
public function set_custom_style($names, $paths)
{
$paths = (is_string($paths)) ? array($paths) : $paths;
$names = (is_string($names)) ? array($names) : $names;
// Set as __main__ namespace
$this->twig->getLoader()->setPaths($paths);
// Add all namespaces for all extensions
if ($this->extension_manager instanceof \phpbb\extension\manager)
{
$names[] = 'all';
foreach ($this->extension_manager->all_enabled() as $ext_namespace => $ext_path)
{
// namespaces cannot contain /
$namespace = str_replace('/', '_', $ext_namespace);
$paths = array();
foreach ($names as $style_datas)
{
if (!isset($style_datas['ext_path']))
{
$ext_style_path = $ext_path . 'styles/' . $style_datas['name'] . '/';
$ext_style_template_path = $ext_style_path . 'template/';
}
else
{
$ext_style_template_path = $ext_path . $style_datas['ext_path'];
$ext_style_path = parent_dir($ext_style_template_path);
}
if (is_dir($ext_style_template_path))
{
// Add the base style directory as a safe directory
$this->twig->getLoader()->addSafeDirectory($ext_style_path);
$paths[] = $ext_style_template_path;
}
}
$this->twig->getLoader()->setPaths($paths, $namespace);
}
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment