🔥 CodeIgniter Intermediate

What is CI4's View Layouts system?

Answer

CodeIgniter 4 provides a simple but effective View Layouts system for template inheritance without a full templating engine. Create a layout file in app/Views/Layouts/main.php: <?= $this->renderSection("content") ?> marks where child content goes. In a child view, extend the layout: <?= $this->extend("Layouts/main") ?> and define the content section: <?= $this->section("content") ?>My page content<?= $this->endSection() ?>. Include another view: <?= $this->include("partials/header") ?>. You can have multiple sections in one layout (e.g., content and scripts). Layouts provide the template inheritance functionality that was traditionally handled by third-party libraries in CI3. For more powerful templating with variables and filters, integrate Twig via Composer.