Part of the EllisLab Network
   
1 of 3
1
Introducing the Template Library
Posted: 29 July 2008 04:15 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2272
Joined  07-27-2006

Hey all! I’m excited, after weeks of preparation and months of iterative tweaking, to finally release my first full contribution to the CodeIgniter community: The CodeIgniter Template library.

Template Library homepage

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->load();

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

Well, it’s late and the sleeping pills are kicking in, so I hope I haven’t overlooked anything in this release. I’ll be around for support, of course.

Cheers! tongue wink

 Signature 

Check out the Template Library
Oh yeah, I tweet, too.

Profile
 
 
Posted: 29 July 2008 04:41 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  9
Joined  04-15-2008

good library, i like it, thx.

Profile
 
 
Posted: 29 July 2008 05:56 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  297
Joined  05-04-2008

This looks great. I may use it in my current project. Kudos on the detailed user guide!

 Signature 

[ Adam Griffiths - Shropshire Based Web Developer ]
[ The Authentication Library User Guide ]
[ Programmers Voice - Blog about the internet, code and development ]

[ Follow me on Twitter ]

Profile
 
 
Posted: 29 July 2008 06:31 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  708
Joined  03-20-2006

Loving the name, i personally can’t stand stupid names for stuff. Having used joomla a fair bit it looks pretty stupid when you have http://joe.com/index.php?com_ilovecowsforms in your urls.

Profile
 
 
Posted: 29 July 2008 06:47 AM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
RankRankRankRank
Total Posts:  2139
Joined  07-30-2007

http://joe.com/index.php?com_ilovecowsforms

404 :D

In all seriousness, with CI it doesn’t matter what the library is called - you generate your own URLs.

 Signature 

Follow me on Twitter
MichaelWales.com

Profile
 
 
Posted: 29 July 2008 06:54 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  708
Joined  03-20-2006

Of course it was a fake url and also a made up joomla component!

I know it doesn’t matter with CI (i do know a little bit about ci…!) but it still irks me.

Profile
 
 
Posted: 29 July 2008 01:01 PM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2272
Joined  07-27-2006

Kudos on the detailed user guide!

Your welcome! It actually took longer, much longer, to finish than the library. Also, writing it exposed problems with the code and ideas for more features. It’s a good exercise that serves everybody well.

Loving the name, i personally can’t stand stupid names for stuff.

Amen. Like I state in the user guide, I wanted it to read well when encountered in the code. Although it is important at times to have more unique, less generic naming standards in big communities, I think I can still get away with it here. There currently is an exactly named library in the Wiki that does something quite different.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too.

Profile
 
 
Posted: 30 July 2008 07:30 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  607
Joined  05-28-2008

Okay, I thought I’d use this, seeing as I didn’t really like my current way of working and now I have to deal with a multi controller application I thought this would really help me.

But I just can’t get it to work. It’s probably something stupid, but here goes nothing.

I left the config file as it was, only changed the standard view file template.php into index.php which looks like this:

<?php
    
echo $header;
    echo
$content;
    echo
$footer;    
?>

(Previously, those were just the places I loaded the viewfiles, I passed a variable from my controller to determine which content view should be loaded.

Now I’ve put this in my controller construct:

$this->template->load();
$this->template->write_view('header', 'partials/header', $data);
$this->template->write_view('footer', 'partials/footer');

But I just get a blank page. My regions match with the ones set (as standard) in the config file, but nothing…

Also, a feature request: you can pass content (in an array) in the config file, wouldn’t it be handy if we could pass it view files too?


Edit: Okay, I feel stupid, didn’t look at the example properly, now it’s working like a charm. Didn’t need to do the load thing in the construct, needed to do it LAST (not first) in my preferred method, only need to write to header and footer in the construct.

 Signature 

Bramme.net webdevelopment
If I had a nickel for every time someone told me that my idea for melting down coins to make a giant robotic parrot was a bad idea, I would have one kicka$$ giant robotic parrot.

Profile
 
 
Posted: 30 July 2008 10:53 AM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2272
Joined  07-27-2006

Glad you solved it, bramme. The docs could be a little more clear on how important the load() method is and what it does. It is the final step, taking all your regions and sending them to the master template.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too.

Profile
 
 
Posted: 30 July 2008 11:27 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  607
Joined  05-28-2008

Yeah, I think I could confused because you first talk about template->load. Load is most of the time a command you use first in CI. Maybe you could/should rename to something like “initiate”? Though that’s often used second. Tough one…

Anyhoo, what about my feature request? I can imagine it’s not that difficult? Maybe add a fifth array key for the config, view?

 Signature 

Bramme.net webdevelopment
If I had a nickel for every time someone told me that my idea for melting down coins to make a giant robotic parrot was a bad idea, I would have one kicka$$ giant robotic parrot.

Profile
 
 
Posted: 30 July 2008 01:10 PM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2272
Joined  07-27-2006

wouldn’t it be handy if we could pass it view files too?

Well, if you’re views aren’t dynamic (they don’t require data being passed in), then there’s really no reason to not just include them in the master template, like, not separate them out into their own files. I guess there could be a reason to share Views among different templates like that, though, in which case it makes since to separate them out. I will certainly consider it.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too.

Profile
 
 
   
1 of 3
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 719, on June 06, 2008 10:16 AM
Total Registered Members: 77530 Total Logged-in Users: 30
Total Topics: 101537 Total Anonymous Users: 3
Total Replies: 544308 Total Guests: 271
Total Posts: 645845    
Members ( View Memberlist )