Welcome Guest, Not a member yet? Register   Sign In
Extending View?
#1

(This post was last modified: 05-06-2020, 10:20 AM by easyD.)

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

"../layout.php"
"Views/..path../layout.php"

but nothing seems to work.

Any suggestion on how to solve this issue?

[Image: view.jpg]

Edit...

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")?
Reply
#2

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.
Reply
#3

(This post was last modified: 05-06-2020, 11:27 AM by easyD.)

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); 

        return 
$view->setVar('data'$data)->render('customer/dashboard'); 

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




Theme © iAndrew 2016 - Forum software by © MyBB