I am trying to integrate blade template engine in CodeIgniter framework using library method.
Here are the steps I followed
1.Download the blade template engine via composer and copy to application/libraries
folder.
2.Created a class named Bladetemplate
in libraries folder
Bladetemplate.php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once dirname(__FILE__).'/blade/vendor/autoload.php';
use Philo\Blade\Blade;
class Bladetemplate {
public function loadTemplate(){
$views = APPPATH. '\views';
$cache = APPPATH. '\cache';
$blade = new Blade($views, $cache);
return $blade;
}
}
3.In my controller file, I've loaded the library and call the function loadTemplate
for blade template view
public function index()
{
$this->load->library('Bladetemplate');
//template object
$obj= $this->bladetemplate->loadTemplate();
$obj->view()->make('test',array('data'=>'test'))->render();
}
In my applications/views
folder file named test.blade.php
is present
There is no error is shown, but nothing displayed on the page ( some HTML contents are present).
Change your view file name to add .blade. Like if your view file test.php than make it test.blade.php
Instead of $obj->view()->make('test',array('data'=>'test'))->render();
you need to use $obj->view()->make('test.blade',array('data'=>'test'))->render();
Whenever you are using blade template, you have to render your view as blade type. So, test.blade
I hope, It will work.
If not, let me know.