• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extending View?

Hello! I'm trying to extend dashboard.php view with layout.php view. Layout.php is one level up compared to dashboard.php.

I tried


but nothing seems to work.

Any suggestion on how to solve this issue?

[Image: view.jpg]


I found out that this is working... "themes\default\layout". Any other solutions whit which I would avoid using the name of the theme (so in this case - theme with name "default")?

The way I've handled this is to create a new instance of the renderer service, giving it the path to my themes folder:

PHP Code:
$path ROOTPATH ."themes/{$this->theme}";
$renderer Services::renderer($pathnullfalse); 

Passing false as the last argument gives you a non-shared instance. Now, when you use things like $this->extend(), or $this->include() within your views, it will always find it within your theme directory. In the example I linked to, it supports multiple themes within the Themes directory.

If you need to get a view from the normal path anywhere, you can still use echo view('...'), which uses the main, shared, instance of the View library that points to the default location.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4

Killishan thank you very much! It works Smile  This is the code I wrote based on your suggestion. 

PHP Code:
        $path APPPATH 'views/themes/default/'// {$this->theme}

$view = \Config\Services::renderer($pathnullfalse); 


So now I can in views files use only <?= $this->extend('layout'?> for extending the view.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.