Skip to content

SalFay/Codeigniter-Blade-Theme-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Codeigniter-Blade-Theme-Engine

This library integrates Laravel's Blad Engine into Codeigniter with a theming functionality so you are not only limited to displaying views in the traditional CI style but it gives you the power to have as many themes as you want in one CI installation and you can switch themes anytime and anywhere you want.

Installation

  1. Clone/Download this repository.
  2. Copy all files to your CodeIgniter folder.
  3. Open application/config/autoload.php
  4. Add theme to the following arrays
    $autoload['libraries'] = array('theme');
    $autoload['helper'] = array('theme','url');
    $autoload['config'] = array('theme');

Install Blade Package

We are using duncan3dc/blade which is a standalone package of Blade. So Install the said package via Composer by issuing this command

composer require duncan3dc/blade

Make sure you have Configured Using Composer with your CodeIgniter in config.php file

Configuration

  1. Create a Directory themes in your CodeIgniter's root directory
  2. You are free to Change the name of themes directory
  3. Create default directory in the themes directory
  4. Open application/config/theme.php
  5. You can see some Configuration items.
  6. If you have changed the name of themes directory, configure that in
    $config['theme_directory'] = FCPATH.'themes'.DIRECTORY_SEPARATOR;
  7. If you have changed the sub directory of themes from default to something else, Configure that in
    $config['theme_default'] = 'default';

Usage

In the application/config/theme.php file, You have configured the default theme name. Which will be used as your default directory where the library will look for views/template files.

Go to themes/default directory and create welcome.blade.php file.

Paste the following Text in that file.

<DOCTYPE html>
<html lang="en">
<head>
	<title>{{$page_title}} - CodeIgniter</title>	
</head>
<body>
<h1>Welcome {{$person_name}}!</h1>
</body>
</html>

Now in your controller, do the following

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public function index()
	{
	    $view_data = array(
	        	'page_title' => 'Blade template Engine came to CodeIgniter',
			'person_name' => 'Fayaz Khan'
        	);
		$this->theme->display('welcome',$view_data);
	}
}

That's it, Navigate to /welcome and you will see the Blade template engine working the way you want,

Documentation

You can find usage and all documentation of Blade Template engine @ Laravel Official Website

Contribution, Feedback and suggestions

This is the initial version of blade theming engine. I am looking forward to see your feedback and suggestions. I will be adding more features to this library as I get free time.

Happy Coding

Releases

No releases published

Packages

No packages published

Languages