CodeIgniter-Template is a Template library that helps your build complex views with CodeIgniter. It has logic to work with themes & modules and helps add your title, meta-data, breadcrumbs and partial views. Site Templates; PHP Scripts; Free Download CodeIgniter integrated with AdminLTE Template (Nulled) Latest Version Do you want to build CMS or Administrator System or Backend System? Download WordPress Themes & Plugins - Download WordPress Themes & Plugins. WordPress Themes. Overview -Admin Plus – Codeigniter ready Backend for any website or Applications. Admin Plus is a Codeigniter based CMS backend admin dashboad. Which will help you to start any type of project with its common features.
Example
How you usually load a view:
How you load a view into a template with this library:
This loads the view about.php
into template.php
.
Installation
- Put
Template.php
intoapplication/libraries
How to use it
Create a template file
application/views/template.php
$contents
is where your view will be inserted.
Create a view
application/views/about.php
Load the view into the template
In your controller:
How this library works
The view is loaded into a variable which is passed to the template.
Advanced use 1: more slots in your template
Example: you want to set the page title.
Add an HTML header to views/template.php
Set the title in your controller before loading the view:
Advanced use 2: highlight the current navigation item
Navigation is usually part of the template. However, it's a good practice to highlight the item corresponding to the current page, so your visitors know where they are.
Define your navigation items
Add to application/libraries/Template.php
under $this->set('contents...
:
Update your template
Add in application/views/template.php:
To be able to use the anchor
function, autoload the url
helper in config/autoload.php
:
Update your controller
Add:
Notes:
- if all methods of your controller are under the same nav item, you can set the nav directly in the constructor.
- to actually highlight the current item, define the corresponding CSS (for
#navigation .selected
).
Advanced use 3: multiple templates
To easily deal with multiple templates, define new load methods in libraries/Template.php
instead of modifying the existing one. Advanced use 2 with a custom method:
Corresponding code in your controller:
Misc
Last update: November 10, 2011 (updated folder paths for CodeIgniter 2). Previous version is still available.
Contributors:
- Moshe Teutsch: view loading with CI method instead of include_once. That makes things much cleaner and simpler!
Feedback
I know i'm being dense, but how would you change the nav_list items anchor build? Say you want the menu item in the nav list to say Photos but the link itself for navigation purposes needs to point to a controller that may not be named photos?
It will build like
http://www.someplace.com/ci-app/photos
but i really need
http://www.someplace.com/ci-app/gallery/add
You're not being dense at all.
In libraries/Template.php
, set nav_list like that:
Then in views/template.php
:
Jan 22, 2009
#4
Apr 7, 2009
#12
May 14, 2009
#16
You can call $this->template->load() from the error_404() method.
May 26, 2009
#21
http://codeigniter.com/forums/viewthread/121545
Jul 17, 2009
#34
Aug 31, 2009
#44
http://codeigniter.com/user_guide/general/views.html
Oct 22, 2009
#54
Jan 9, 2010
#60
function parser($template = ', $view = ' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
$this->CI->load->library('parser');
$this->set('contents', $this->CI->parser->parse($view, $view_data, TRUE));
return $this->CI->parser->parse($template, $this->template_data, $return);
}
www.niloofaran.com
#
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: nav
Filename: views/template.php
Line Number: 14
'> Home
Do you have any advice
send reply to 'pskumr65@gmail.com'.
thakyou all...
I keep all my templates in a sub folder of my views for organizational purposes, so to access them I would have to type:
$this->template->load('templates/template', 'view', $data);
To remove the subdirectory from the function call I did this.
I added this to the library:
var $template_path = 'templates/';
and then within the load function, I altered it to this:
$this->CI =& get_instance();
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
return $this->CI->load->view($this->template_path.$template, $this->template_data, $return);
This allows to me to change the path to the template file with one line of code and shorten the function call. However if you have multiple developers you may need to inform them about this behavior. Hope this helps!
This doesnt work
<?= $contents ?>
Need to change this as
<?php echo $contents; ?>
Why is that
short_open_tag = Off
This disables use of <? =
PhpKiddo grows a year more :)
Mar 19, 2010
#69
Not sure what I am doing wrong but I keep getting the following error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: contents
Filename: views/template.php
Line Number: 11
Apr 19, 2010
#71
Apr 19, 2010
#72
controllers/products.php
class Products extends Controller {
function Products()
{
parent::Controller();
}
function index()
{
$this->template->load('template', 'about');
}
}
views/template.php
<html>
<body>
<div><?= $contents ?></div>
<div>Copyright 2008</div>
</body>
</html>
views/about.php
<h1>About</h1>
<p>I'm so human!</p>
Please let me know if you see something wrong.
I uploaded this libraries Template.php as Template2.php, changed the class name to Template2 inside of it, changed the autoload entry to 'template2' and called $this->template2->load
inside of the controller. Everything worked!
I am new to CI, but I would think that the CI Template.php file would be systemlibraries folder - any thoughts?
Jun 2, 2010
#79
Jun 8, 2010
#82
CSS/JS loading.
e.g. add, display
I'm also adding a method to set the template. I like to set the template in the constructor. Also if I choose to add functionality for the user to change the template.
e.g. set_template
Jul 12, 2010
#84
example:
<div?> <?= $menu; ?></div> <-- this will load html view menu
<div?> <?= $content; ?></div> <-- this will load view html content
<div?> <?= $footer; ?></div>
it is just like face book like Tom post a comments and there friends comments on tom comments
<?php $statsid=$rows->status_id; ?>
<?php foreach($query2->result() as $rs):?>
<li>
<div>
<div><img >config->item('base_url').$rows->profile_picture_path;?>' /></div>
<div>
<span><?=$rs->user_name;?> </span><?=$rs->status_comment;?>
</div>
</div>
</li>
<?php endforeach;?>
Best regards :)
i have this problem:
#
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: nav
Filename: views/template.php
Line Number: 10
'> Home
for all links
this is my template.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Template {
var $template_data = array();
function set($name, $value)
{
$this->template_data[$name] = $value;
}
function load($template = ', $view = ' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
$this->set('nav_list', array('Home', 'Web sites', 'Grafica', 'Contact'));
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
return $this->CI->load->view($template, $this->template_data, $return);
}
}
/* End of file Template.php */
/* Location: ./system/application/libraries/Template.php */
i'm a very dummie in php and codeigniter, what is the error?
thank's for script and help
$this->template->set('nav', 'About');
but now all links are for page not found...
i see the helper'html' don't work, is possible the helper 'url' don't work too, but i don't undertand for what.
I'm realy interested in your tutorial.
It worked, and since I'm newbie, but my job demands me to get along with codeigniter and javascript. I wanna know, what would it looks like if the changing of the page content of your 'simple sample' was triggered by a button click,which means you have to include some script to make it happen? I hope I could see your reply, ASAP. And I hope you could understand my words, since I'm Indonesian. Thx a lot
thanks in advance!
http://codeigniter.com/user_guide/libraries/parser.html
Feb 16, 2011
#98
$this->CI =& get_instance();
and not:
$this->CI = get_instance();
This is causing all types of problems when using magic methods like __get and __set.
You can load a page inside of a 'themed' template.
The parser is just replacing PHP's code with readable code.
Severity: Notice
Message: Undefined property: Welcome::$template
Filename: controllers/welcome.php
Line Number: 28
If I load the library in the controller like this:
$this->load->library('template');
It works.
I'm still getting my legs with CI but I was under the impression that autoloading a library precluded the need to load it at the controller level. Do I have that wrong?
$autoload['libraries'] = array('form_validation', 'template');
Nice library. Thank you. This is how I imagined the template system would work by default in CI. Very sensible.
I've created an assets folder on the root of my project, with a css folder in it, you only need to put a variable in your code to find the css file and it works fine.
thanks alot
in arabic '???? ??' :D
silly boy that i am i never defined the 'li' tag in my css to 'display: inline'.
working like a charm now.
super library, only started to learn oop yesterday. i can't believe how powerful it is :)
many thanks for sharing this
i.e. sometimes I just want to load the tempalte without any view content, if I don't pass that I get an error 'Unable to load the requested file: .php'
thanks
May 11, 2011
#109
May 16, 2011
#110
I am getting this message when I try to auto load the library as well as load it from my controller.
Message: Undefined property: Home::$template.
Controller code:
$this->load->library('template');
$this->template->load('template');
Config autoload
$autoload['libraries'] = array('template');
Any help would be greatly appreciated!
@allen, put it in ApplicationLibrariesTemplate.php
the problem comes when i want to load the about view with some content in div that has a styling of h2 and p. How do i go about it
I put all the theme in a folder called template in the view folder so when i load i just go with
$this->template->load('template/index', 'blog', $data);
The problem is with css and images.
How can i include css (better dynamically) and js? The files are in 'views/template/css' and 'views/template/js'
Thanks a lot.
M
Thank & Regards,
Nilesh Pangul
<?php
function section(&$name){
echo isset($name) ? $name : null;
}
?>
In the template use:
<?php section($variable)?>
Any tips, folks?
Regards!
Sep 1, 2011
#120
As long as the helper is called in the calling controller, it should work fine.
i just want to ask on how to put link into the menu...
<b>('Home', 'Photos', 'About', 'Contact')</b>
this tutorial is the best!
:)
Cheers!
BTW, very nice work!
this is working great for me, but is it compatible with CI localization support, ie application/language/english/{files}_lang.php ?
I appreciate your work (It helped me a lot), but using short tags instead of the full syntax really had me pulling out my hair.
I'm referring to:
<html>
<body>
<div><?= $contents ?></div>
<div>Copyright 2008</div>
</body>
</html>
Where <?= $contents ?> should really be <?php echo $contents; ?>
If you're developing an app that is to be distributed, you can't rely on short tags always being available.
Just a question. Is it possible to '$this->set' a variable to the view itself instead of the layout file ?
For example if I do
$this->template->set('title', 'toto');
$this->template->load('layout', 'home');
I can call $title in the layout.php file but not in the home.php is it normal ?
Thanks for your help & and of course for your library
Vinz
function load($template = ', $view = ' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
// Added start
if(!empty($this->template_data)){
$view_data = array_merge($this->template_data,$view_data);
}
// end
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
return $this->CI->load->view($template, $this->template_data, $return);
}
And now I can set a variable with $this->template->set('foo','bar'); in the construct controller for example and call it in all methods and views.
Just take care with name conflict I guess
I hope it's not so bad
Vinz
I'm too new in CI, and just try to learn everything about it.
I'm using CI 2.1.0 + this library;
frist install i got some error. but after I try to change :
become :
My first CI can run properly..
thanks for awesome work :D
while setting the 'title' in the controller like below its not working
$this->template->set('title', 'About me');
The error is showing like
Message: Undefined variable: title
function set($data, $value = FALSE)
{
if(! is_array($data)) {
$this->template_data[$data] = $value;
} else {
$this->template_data = $data;
}
}
Now you can pass an array of data, if you are lazy like me and you want to pass in some more data, so instead of writing:
$this->template->set('some_data', 'some value');
you could now do it like:
$tpl_data = array(
'title' => 'About Page',
'meta' => 'CodeIgniter Template library, CI library ...'
);
$this->template->set($tpl_data);
Cheers,
- shkabo
Sep 4, 2012
#133
What nice library! Thanks for share it.
I was doing it on more complex way. ;)
Well, to fill my needs (and allow more clear way to change from my method to yours) I made a few changes on your code, which I would like to suggest you:
1. I've included a test on the library to make sure that the given template is available on the application. If not available, then the library returns the content itself (without a template).
2. I've created 3 new constants to handle the templates' (or layouts) path and place them at ./index.php. This way, if you need to change the structure of application directories (some day) you'll just need to do it on a unique file.
Now, let me show you the changes ...
1. ./application/libraries/Template.php
...
function load($template = ', $view = ' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
/*
* Make sure that the given template exists
* If not exists, then return the content itself.
* The LAYOUT_APP_PATH and LAYOUT_PATH constants are defined at ./index.php
*/
if (file_exists(LAYOUT_APP_PATH.$template.EXT))
{
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
return $this->CI->load->view(LAYOUT_PATH.$template, $this->template_data, $return);
}
else
{
return $this->CI->load->view($view, $view_data, $return);
}
}
...
2. ./index.php
...
/*
|---------------------------------------------------------------
| DEFINE LAYOUT APPLICATION CONSTANTS
|---------------------------------------------------------------
*/
define('LAYOUT_DIR', 'layouts/');
define('LAYOUT_PATH', '../'.LAYOUT_DIR);
define('LAYOUT_APP_PATH', APPPATH.LAYOUT_DIR);
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
...
Well, that's it! What do you think?
Let me know at rogerio [dot] taques [at] gmail [dot] com.
Cheers.
<a href='http://phpflow.com'>phpflow.com</a>
function load($template = ', $view = ' , $view_data = array(), $return = FALSE){
$contentx = $this->CI->load->view($view, $this->template_data, TRUE);
$this->template_data = array(); // Custome me
$this->set('contents', $contentx);
return $this->CI->load->view( $template, $this->template_data, $return);
}
This way i can easily write something like this my controller
$this->template->set('nav_list', array('home','contact','thankyou'));
$this->template->load('column1', 'welcome');
And to imitate your sample code above which says:
Add to application/libraries/Template.php under $this->set('contents...:
$this->set('nav_list', array('Home', 'Photos', 'About', 'Contact'));
You will just have to Add the below code above: [$contentx = $this->CI->load->view($view, $this->template_data, TRUE);]
$this->set('nav_list', array('Home', 'Photos', 'About', 'Contact'));
Jan 2, 2013
#139
Feb 15, 2013
#140
how I can load multi view in template?
your variable is $contents and I can use it once in my template.
I want to use it like:
$this->template->load('template', 'login_form');
$this->template->load('template', 'upload_form');
$this->template->load('template', 'items');
Please Help
Mar 29, 2013
#143
I am having trouble with the link concept. Can you please elaborate more. Or better yet, give an example to an already existing nav. Thank you
Apr 18, 2013
#146
I think that is better put all template page separete from the view folder.
But not work here :-/
Sep 3, 2013
#149
Fatal error: Cannot redeclare class Template in C:xampphtdocsprojectsystemapplicationlibrariesTemplate.php on line 3
how i can fix it ?
i've question , how about to create template
if we have more than one view ex : header.php, body.php, menu.php, footer.php and so on. i don't understand how to figure it w/ your library. thanks for advance jerome :D
May 30, 2014
#154
Jul 7, 2014
#155
Aug 28, 2014
#156
Sep 1, 2014
#157
Sep 4, 2014
#158
I've been using successfully this library on CI2.2.0 and now I'm going to CI 3.0.4 and after updating this library version I'm still facing troubles.
A PHP Error was encountered
Severity: Error
Message: Call to undefined method Template::write_view()
Filename: controllers/perfil.php
Line Number: 35
Please, what am'I doing wrong ?
Thanks in advance
Php Codeigniter Templates Free Download Microsoft
this library really helpful to integrate boostrap with ci
thanks
May 13, 2016
#164
Second, now that it worked, how do I pass data from model into the sub view. You know, that contents view that is inside the body content, not the template itself.
Thanks
Nov 22, 2017
#168
$this->template->load('template','view_admin');
can i use $data ?
why view testing2 not loaded, while the view testing1 loaded
i already copy code on template.php, but still not working
i used CI version 3.1.8
please help me, cause this things waste my time so much
thank you
can you give me a script that I can use this library with CodeIgniter HMVC method ?
This is my folder structure
- xampp
- htdocs
- my_project
- application
- controller
- libraries
- Template.php
- models
- modules
- welcome
- controller
- Welcome.php
- models
- Welcome_model.php
- views
- welcome_view.php
- views
- themes_template.php -----> can I put my template here ?
- third_party
- MX
- Base.php
- Ci.php
- Config.php
- Controller.php
- Lang.php
- Loader.php
- Modules.php
- Router.php
- assets
Your suggestion script that I really appreciate.
Thank you
Aug 23, 2018
#172
Severity: Notice
Message: Undefined property: CI::$books
Filename: MX/Controller.php
Line Number: 59
Backtrace:
File: C:xampphtdocsbookstoreapplicationthird_partyMXController.php
Line: 59
Function: _error_handler
File: C:xampphtdocsbookstoreapplicationmodulesAdmincontrollersAdmin.php
Line: 20
Function: __get
File: C:xampphtdocsbookstoreindex.php
Line: 315
Here is my code:
<?php
class Admin extends MY_Controller
{
function _construct()
{
parent::_construct();
$this->load->module([
'Books'
]);
}
function index()
{
$this->template->call_admin_template();
}
function books()
{
$this->books->display_books();
}
function addBook()
{
$this->books->addBook();
}
}
Free Download Codeigniter ready backend for any website or Applications (Nulled) [Latest Version]
Overview -Admin Plus – Codeigniter ready Backend for any website or Applications
Admin Plus is a Codeigniter based CMS backend admin dashboad. Which will help you to start any type of project with its common features. In this dashboard I have added Advanced website settings with common seo options, Slider Images, Category and 2 label sub category, Posts/Items, Pages, Users & Manage Ads/Banner CURD with ajax authentication. This backend comes with bootstrap 4 material clean and responsive design. It will help you to build any Admin panel, News/Magazine/Blog, CMS, Employee management, CRM, or any backend administrator System.
Demo url
Check Demo
Admin access
Codeigniter Download
username: [email protected] Password: admin
Online Documentation
Check Documentation
Key Features
- Latest CodeIgniter 3.1.7
- Bootstrap 4 & Material Design
- Easy Integration & Customization
- Standared & clean code
- Fully Responsive Design
- Advanced Settings with website SEO options
- Slider Image CRUD
- Category with 2 step subcategory CRUD
- Posts/Items CURD
- Pages CURD
- Users with Role CURD
- Manage website Ads/Banners
- Ajax secure Authentication
- Jquery Data tables
- Jquery form validations
- Ajax pagination with advanced search filter
- Sweetalert popup notification with ajax
- Toaster notification with ajax
- Detailed Documentation with commented code
- Totally Secure System
- Runs on PHP 5.5+ (and PHP 7)
Security
- Cross-Site Request Forgery (CSRF) Prevention
- Cross-Site Scripting (XSS) Prevention
Codeigniter View Template
09/06/2018 – Version 1.0
Kindly Note: We update new contents like WordPress Themes, Plugins, PHP Scripts everyday. But remember that you should never use this items in a commercial website. All the contents posted here for development & testing purpose only. We’re not responsible for any damage, use at your own RISK! We highly recommend to buy Codeigniter ready backend for any website or Applications from the Original Developer (macrotec) website. Thank you.