kenjis / codeigniter-ss-twig

A Simple and Secure Twig integration for CodeIgniter 3.x and 4.x
MIT License
168 stars 46 forks source link

custom directory template #36

Closed wisnubaldas closed 6 years ago

wisnubaldas commented 6 years ago

Hi, I use HMVC and create a module to create an interface on the client side, I want to put the master template in my module, but there is an error like this:

An uncaught Exception was encountered
Type: Twig_Error_Loader

Message: Unable to find template "welcome.twig" (looked into: /home/wisnu/web/gtln/application/views).

Filename: /home/wisnu/web/gtln/vendor/twig/twig/lib/Twig/Loader/Filesystem.php

Line Number: 232

Backtrace:

File: /home/wisnu/web/gtln/vendor/twig/twig/lib/Twig/Loader/Filesystem.php
Line: 150
Function: findTemplate

File: /home/wisnu/web/gtln/vendor/twig/twig/lib/Twig/Environment.php
Line: 329
Function: getCacheKey

File: /home/wisnu/web/gtln/vendor/twig/twig/lib/Twig/Environment.php
Line: 419
Function: getTemplateClass

File: /home/wisnu/web/gtln/vendor/twig/twig/lib/Twig/Environment.php
Line: 362
Function: loadTemplate

File: /home/wisnu/web/gtln/application/libraries/Twig.php
Line: 155
Function: render

File: /home/wisnu/web/gtln/application/libraries/Twig.php
Line: 137
Function: render

File: /home/wisnu/web/gtln/application/modules/front/controllers/Welcome.php
Line: 18
Function: display

File: /home/wisnu/web/gtln/application/libraries/REST_Controller.php
Line: 793
Function: index_get

File: /home/wisnu/web/gtln/index.php
Line: 315
Function: require_once

when I fill out your library following its configuration: in the / module / front / controller directory

class Welcome extends REST_Controller {
    public function __construct()
    {
        parent::__construct();
        $config = [
            'paths' => [APPPATH.'modules/front/views/template'],
            'cache' => APPPATH.'cache/twig',
        ];
        $this->load->library('twig',$config);
    }

    public function index_get()
    {
        $this->twig->display('welcome', ['message'=>'hello']);
    }
}

how to configure my template to be on the module I created? thank you,

kenjis commented 6 years ago

Set all folders where you put your template files in the paths:

$config = [
    'paths' => ['/path/to/twig/templates', VIEWPATH],
    'cache' => '/path/to/twig/cache',
];
$this->load->library('twig', $config);