![]() |
extend layout - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: extend layout (/showthread.php?tid=80516) Pages:
1
2
|
extend layout - nemesis - 11-10-2021 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 RE: extend layout - InsiteFX - 11-11-2021 Sure use an if else statement. RE: extend layout - nemesis - 11-11-2021 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)... RE: extend layout - ikesela - 11-11-2021 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. RE: extend layout - nemesis - 11-11-2021 (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! RE: extend layout - kenjis - 11-12-2021 Do you render the View file, not the Layout in your controller? PHP Code: public function index() RE: extend layout - nemesis - 11-13-2021 (11-12-2021, 11:33 PM)kenjis Wrote: Do you render the View file, not the Layout in your controller? yes, but I think a layout could be used as a standard view as well RE: extend layout - nemesis - 11-15-2021 (11-11-2021, 03:12 AM)InsiteFX Wrote: Sure use an if else statement. could you explain me in detail? I have described my implementation, but as of now I have not yet found an elegant solution - thanks! RE: extend layout - kenjis - 11-15-2021 Without the change of system\View.php, doesn't your layout work? RE: extend layout - nemesis - 11-16-2021 (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 |