![]() |
Hi,
i try to create a layout-template. For that i start with this: add a template function to the base-controller Code: public function template(string $page, array $data) in the central template view "create_page" i want to add/include more additional files, for example 1 file for the header, 1 file for sidenav etc. So i trie this: Code: <?= view('templates/v1/view_file_header') ?> Code: <div id="header" class="app-header">here content from view_file_header<?= $this->renderSection('header') ?></div> In my "view_file_header" Code: <?= $this->extend('templates/v1/create_page') ?> In my "view_file_sidebar" Code: <?= $this->extend('templates/v1/create_page') ?> At the end, it doesnt work for me. I recieved a error 500. Changing the from "view('templates/v1/view_file_sidebar') " to "$this->include('templates/v1/view_file_sidebar')" makes no difference. What i do wrong?
In my opinion, the template does not work like that. It is necessary to expand "Create_Page" once and create sections for it. There should be no other "extend" inside
My central page looks like this:
Code: <body class="hold-transition sidebar-mini"> Then, any sub-page uses this format: Code: <?= $this->extend('Modules\Views\Admin\page') ?> This might not be perfect, but it works for me.
ok,i test a bit -by the way is there a way (or to need), to pass the ($DATA) data-variable from the controller for the main view (central layout page) in my example the "create_page(path,$DATA) to the other sub-views by inlcuding or if i try to use the way with " $this->extend('templates/v1/create_page') " ?
I usually pass $data in a sub-page, including data for top and side navigation like this:
PHP Code: echo view('Modules\Admin\Departments\Views\index', $data);
In this case i think the $data from controller need also a $data['data']=this is for subpage, isnt it?
(12-10-2024, 01:34 AM)JustJohnQ Wrote: My central page looks like this: If i use: "<?= $this->extend('templates/v1/page_content') ?>" in my subpage i recieved a error 500. I dont understand why? If i dont use the "extend" command, all works fine - i'm confused...
I think you are making it more complicated than necessary, pleasae look at these guidelines in the documentation:
https://codeigniter4.github.io/userguide...youts.html Start with a basic setup, and work from there. I am never calling Code: Modules\Views\Admin\page In a fresh CI 4.51 installation, I created 3 files in the App\Views folder: create_page.php Code: <!DOCTYPE html> header.php Code: <section class="content-header"> home.php Code: <?= $this->extend('Views\create_page') ?> I changed the line with welcome_message in Home controller to: PHP Code: return view('home'); The result is: ![]() |
Welcome Guest, Not a member yet? Register Sign In |