![]() |
Hi, I'm wondering if a layout can define a default behavior that is used when the section is not defined in the view extension.
it's possible? thanks, Paolo
Sure use an if else statement.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I am sorry, I'll be more precisely with some examples. this is my view:
Code: <?= $this->extend('default'); ?> Code: <!doctype html> I've try to change system\View.php from Code: public function renderSection(string $sectionName){ to: Code: public function renderSection(string $sectionName){ so that my layout become: Code: <!doctype html> this work fine but it isn't the right way! I will not change system source code... more over, it do a wrong render when I use multiple times (one inside another)...
layout.php (in App\VIew folder)
Code: <!doctype html> some_file.php Code: <?= $this->extend($config->viewLayout) ?> your_controller Code: public function your_function() YourConfig.php (in App|config folder) Code: namespace App\Config; Routes.php Code: $routes->get('/', 'YourController::your_function'); I hope this can give you hint how the layout basic work and load it as single page web You can edit file App\View\errors\html\error_404.php for custom not found page and remove default message. (11-11-2021, 09:45 AM)ikesela Wrote: thanks for the reply, but I can't understand what it has to do with my problem.. I would like to be able to define a layout that generates a complete view (with basic html for all sections), which can possibly be (partially or even totally) redefined by the view. I await suggestions!
Do you render the View file, not the Layout in your controller?
PHP Code: public function index()
Without the change of system\View.php, doesn't your layout work?
(11-15-2021, 06:40 PM)kenjis Wrote: Without the change of system\View.php, doesn't your layout work? does not work! since renderSection ($sectionName) does not return any value, how does the layout file know if it has been used? that is, if section($sectionName) has been called change was in system\View\View.php: PHP Code: public function renderSection(string $sectionName){ PHP Code: <?php if (!$this->renderSection('aSection')): ?> but I think it doesn't work in case of nested use |
Welcome Guest, Not a member yet? Register Sign In |