Part of the EllisLab Network
   
1 of 2
1
Template Library Version 1.2.1
Posted: 08 August 2008 01:38 AM   [ Ignore ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2916
Joined  07-27-2006

Template Version 1.3 has been released.

Template Library Version 1.2.1 has been released. Version 1.2.1 fixes a major bug found in 1.1 and 1.2 with the add_css() and add_js() methods. Upgrade RECOMMENDED.

——————————————————————————————————————————-

Visit the Template Library Homepage

View the Change Log

Still using Template 1.2? See the Ignited Code thread covering Template 1.2

——————————————————————————————————————————-

The Template library, written for the CodeIgniter PHP-framework, is a wrapper for CI’s View implementation. Template is a reaction to the numerous questions from the CI community regarding how one would display multiple views for one controller, and how to embed “views within views” in a standardized fashion. In addition, Template provides extra Views loading capabilities and shortcuts for including CSS, JavaScript, and other common elements in your final rendered HTML.

Using Template looks like this:

$this->template->write('title', 'Introduction to Template');
$this->template->write_view('content', 'blog/posts', $this->blog->get_posts());
$this->template->render();

Look interesting? Head over to the Template Library Homepage to begin using Template in your next CodeIgniter application.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 08 August 2008 12:05 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  840
Joined  02-05-2007

Hi Colin. Could you explain the advantages of the Template library in comparison to CI’s default method?

Template Library:

$this->template->write('title', 'Introduction to Template');
$this->template->write_view('content', 'blog/posts', $this->blog->get_posts());
$this->template->render();

CI default:

$data['title'] = 'Introduction to Template';
$data['content'] = $this->load->view('blog/posts', $this->blog->get_posts(), true);
$this->load->view('template', $data);
 Signature 

“I am the terror that flaps in the night”

Profile
 
 
Posted: 08 August 2008 02:09 PM   [ Ignore ]   [ # 2 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2916
Joined  07-27-2006

Sure, Rick. When one starts using views, they realize they can achieve segmenting views and load results of those in to a master “template” view, like your rewriting of my example shows. However, components of this master template view often don’t change between Controller methods, or even controllers. To address the former condition, we can extract or $data array out to a property of the given controller:

class Blog extends Controller {
   
var $tpl = array('title' => 'Introduction to Template');
   
   function
index()
   
{
      $this
->tpl['content'] = $this->load->view('blog/posts', $this->blog->get_posts(), true);
      
$this->load->view('template', $this->tpl);
   
}
}

What Template and other similar Libraries do is abstract that out one level further. A region in my Template Library is no different than an item in a $data array that is passed to views. However, it is available for manipulation in a greater amount of contexts. Also, multiple calls to write to a region will concatenate the content—again, not impossible with vanilla CI and views, but there’s slightly more overhead when having to be keen to the given context. And a feature I built into Template that I call Cascading Views, by which you can provide fall-back view files if the requested on doesn’t exist, for example, is something you won’t find in CI’s Views implementation.

Some people will never have a problem working with Views and View data in the manner you showed. Some people will. Others, like myself, just like the abstraction that such a library affords (and I personally like the metaphors and syntax Template promotes.)

It’s a free-for all with how you manage Views and View data. Template standardizes this management for those who prefer it standardized.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 08 August 2008 03:12 PM   [ Ignore ]   [ # 3 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2916
Joined  07-27-2006

Also, I might as well quote from my own user guide:

Template is right for you if

  * You feel like using views can be clunky, especially when “embedding” views.
  * You don’t like calling header, footer, and other global views from every Controller method.
  * You prefer having one “master template” that can be changed for any controller in order to meet unique application design needs.
  * You don’t want to drastically alter the way you interface controllers and views.
  * You like clear, thorough documentation on par with CodeIgniter’s User Guide.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 08 August 2008 04:08 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  412
Joined  05-30-2008

I might check it out wink

Profile
 
 
Posted: 09 August 2008 07:24 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  447
Joined  05-21-2007

I think you did a great job writing the documentation, good luck with your stuff.

 Signature 

-> None official irc channel [ irc.freenode.net #codeigniter ]

Profile
 
 
Posted: 11 August 2008 04:05 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  131
Joined  06-06-2008

Is it possible to change the extension of the template files? From template.php to template.tpl or something similar?

 Signature 

Milos Dakic
JustHost - world class hosting
Library: Events Library

Profile
 
 
Posted: 11 August 2008 04:36 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  47
Joined  12-22-2007

Looks really good, but from what i could see it would be hard to intergrate into my current project

 Signature 

Go to WebSiNcH Hosting for the ULTIMATE free hosting and FREE installation of CodeIgniter (if you want it that is)

Profile
 
 
Posted: 11 August 2008 04:38 AM   [ Ignore ]   [ # 8 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2916
Joined  07-27-2006

Sure, Milos. Name your template whatever.tpl and in config/template.php, set:

$template['group']['template'] = 'whatever.tpl';

If Views can handle it, Template can handle it (Template is just an interface to Views.)

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 11 August 2008 04:41 AM   [ Ignore ]   [ # 9 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2916
Joined  07-27-2006

Looks really good, but from what i could see it would be hard to intergrate into my current project

Totally understandable and expected. It is definitely an approach one wants to consider up front. With a large project running just fine using standard Views loading, there isn’t a lot of sense in refactoring to use Template, unless specifically needed/warranted.

Also remember that Template and Views go hand-in-hand and can exist side-by-side, method-by-method. Say an app needed a new/alternative output format, say RSS or some bespoke XML, Template could be loaded and used in only the needed contexts.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 11 August 2008 04:46 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  131
Joined  06-06-2008

One more question Colin, were you looking at adding support for Smarty in this? Or how hard would be be to add support for Smarty?

I would very much like to use your library, but at this point in time I’m looking to use a template engine as the Parser library that comes with CI is not adequate enough for what I’m trying to do.

If I do choose to use your library, it will be used for a commercial project that I have been planning to make for some time now. Are you fine with that?

 Signature 

Milos Dakic
JustHost - world class hosting
Library: Events Library

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120541 Total Logged-in Users: 36
Total Topics: 126599 Total Anonymous Users: 3
Total Replies: 665562 Total Guests: 353
Total Posts: 792161    
Members ( View Memberlist )