Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] HMVC current module path
#1

[eluser]Davide Bellini[/eluser]
Hi guys!
I'm integrating Twig Template library in CI with HMVC.

I want insert html template page in module/views folder, like this :

- module_name
- controllers
- module.php
- models
- module_model.php
- views
- module_view.html
- module_view1.html
- ...

How can I retrieve current module "views" path??
I've to set this path in Twig_Loader_Filesystem(array("MODULE_VIEWS_PATH"));

Cheers


UPDATE :
I found a solution for my problem ... I've used :
Code:
$module_info = Modules::find($view_name, $this->router->class, 'views/');
$module_view_path = (isset($module_info[0])) ? $module_info[0] : '';
$module_view_name = (isset($module_info[1])) ? $module_info[1] : '';

and retrieve :
Code:
array(
[0] => 'C:\WEBROOT_PATH/application/modules/test/views/'
[1] => 'test.html'
)

Hope this is helpful
#2

[eluser]Unknown[/eluser]
Hi,

Thank you, your solution is good and is a good start point.

Unfortunately, It's not at all good for me because i need inherit from a base template in all my templates.

I use the CodeIgniter Twig Integration Library (altrano)

My solution was as follows:

- In the config file application/config/twig.php:
Code:
$config['template_dir'] = APPPATH.'views'; //For global Templates

- In the library application/libraries/Twig.php:
Code:
Twig_Autoloader::register();

//HMVC patch by joseayram
$template_module_dir = APPPATH.'modules/'.$this->CI->router->fetch_module().'/views/';
$template_global_dir= $this->CI->config->item('template_dir');
$this->_template_dir = array($template_global_dir, $template_module_dir);
//end HMVC patch
        
$this->_cache_dir = $this->CI->config->item('cache_dir');

$loader = new Twig_Loader_Filesystem($this->_template_dir);

Hope this is helpful too for someone
#3

[eluser]Unknown[/eluser]
Thank you joseayram,

I changed this line to give me access to the "Contexts" in CIBonfire - https://github.com/ci-bonfire/Bonfire/wiki/Contexts

Code:
$template_module_dir = APPPATH.'modules/'.$this->CI->router->fetch_module().'/views/'.$this->CI->router->fetch_class();

I used - https://github.com/dilantha/codeigniter-twig




Theme © iAndrew 2016 - Forum software by © MyBB