HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Adding a custom path to Twig

Hello, I need help:


How can I change or add a new path to twig?


Thanks

Comments

  • I changed line `66` of the file library/Vanilla/Web/TwigRenderTrait.php to the correct diretory.

    A did so to solve (to patch) a bug I had, as exposed here https://open.vanillaforums.com/discussion/37561/upgrading-from-3-1-to-3-2-fatal-error-in-twig-loader-filesystemloader-findtemplate

    VANI
     61   public function renderTwig(string $path, array $data): string {
     62     if (!$this->twig) {
     63       $this->twig = $this->prepareTwig();
     64     }
     65     // Ensure that we don't duplicate our root path in the path view.
     66     $path = str_replace('/home/user/VANILLA-FILES', '', $path);
     67     return $this->twig->render($path, $data);
    
    

    If there is better way to do this please tell me :)

  • @kassius If you could raise this as an issue on GitHub, it would get to the attention of the developers.

  • I think you can achieve this by using addPath in the library/Vanilla/Web/TwigRenderer.php file constructor, like this:

    class TwigRenderer extends \Twig\Environment {
    
      /**
       * DI.
       *
       * @param TwigEnhancer $enhancer
       * @param ConfigurationInterface $configuration
       */
      public function __construct(TwigEnhancer $enhancer, ConfigurationInterface $configuration) {
         
    		$loader = new \Twig\Loader\FilesystemLoader(PATH_ROOT);
    		$loader->addPath('<your_additional_path>');
    
Sign In or Register to comment.