🔥 CodeIgniter Intermediate

What is CI4's View Layouts system?

Why Interviewers Ask This

This question targets practical, hands-on experience with CodeIgniter. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

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.

Common Mistake

Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong CodeIgniter candidates.