A library that will help you to create templates for your CodeIgniter 4 application.
- Copy the
app/Libraries/Template.php
file to yourapp/Libraries
folder. - Copy the
app/Views/template.php
file to yourapp/Views
folder.- Create a folder named
home
in yourapp/Views
folder. - Create a folder named
layout
in yourapp/Views
folder.- Now create 2 files named
header.php
andfooter.php
in yourapp/Views/layout
folder.
- Now create 2 files named
- Create a folder named
- Load the library in your controller:
use App\Libraries\Template;
before the controller class. - Now you can use the library in your controller like this:
Template::Home("view_name")
Template::Home("view_name", $data)
Template::Home("view_name", $data, 'template_folder_name')
this will be the folder where you havelayout
Template::YouCustomFunction("view_name", $data)
For the sack of example I have create a Admin
function in the Template.php
file. You can create your own functions and use them in your controller.
I have already created a folder in the view with the name of admin_side
, and I use that folder in the Admin
function.
In Home controller you can see I covered all the examples.
PS: You're free to use this library in your project, if you have any questions you can open an issue, also you can contribute to this library.