For any queries you can reach us at / WhatsApp us: +919158876092

Include header and footer in CodeIgniter 4

How to include header footer

First of all, create a common file in the view folder. In this example, I have created a file name as template.php in /app/Views/innerpages directory.

File structure:
	+ innerpages
		- footer.php
		- header.php
		- template.php
	- home.php

	- Home.php



	echo view('innerpages/header.php');
	echo view($main_content);
	echo view('innerpages/footer.php');


In the above example, $main_content is a dynamic view for each page.


<!DOCTYPE html>
<title><?php echo $title; ?></title>


<h1><?php $heading; ?></h1>



namespace App\Controllers;
use App\Controllers\BaseController;

class Home extends BaseController {

	public function index() {
		$data = [];
		$data['title'] 		= 'Page Title';
		$data['heading']	= 'Welcome to'
		$data['main_content']	= 'home';	// page name
		echo view('innerpages/template', $data);



<h4> Welcome to Home </h4>