Last active
December 21, 2015 22:58
-
-
Save xwero/6378648 to your computer and use it in GitHub Desktop.
Load twig templates from the lib directory of your module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\module_name\Controller; | |
use Drupal\Core\Controller\ControllerInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Drupal\Core\Template\TwigEnvironment; | |
class FooController implements ControllerInterface { | |
public function __construct(TwigEnvironment $twig, $twig_loader) { | |
$twig_loader->addpath(str_replace('Controller','View',__DIR__)); | |
$this->twig = $twig; | |
} | |
public static function create(ContainerInterface $container) { | |
return new static( | |
$container->get('twig'), | |
$container->get('twig.loader') | |
); | |
} | |
public function displayTwig(){ | |
return $this->twig->render('displayTwig.html.twig'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment