ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Introducing the Template Library

July 29, 2008 6:15am

Subscribe [9]
  • #1 / Jul 29, 2008 6:15am

    Colin Williams

    2601 posts

    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! 😜

  • #2 / Jul 29, 2008 6:41am

    dinda

    6 posts

    good library, i like it, thx.

  • #3 / Jul 29, 2008 7:56am

    Adam Griffiths

    316 posts

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

  • #4 / Jul 29, 2008 8:31am

    johnwbaxter

    651 posts

    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.

  • #5 / Jul 29, 2008 8:47am

    Michael Wales

    2070 posts

    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.

  • #6 / Jul 29, 2008 8:54am

    johnwbaxter

    651 posts

    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.

  • #7 / Jul 29, 2008 3:01pm

    Colin Williams

    2601 posts

    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.

  • #8 / Jul 30, 2008 9:30am

    Bramme

    574 posts

    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.

  • #9 / Jul 30, 2008 12:53pm

    Colin Williams

    2601 posts

    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.

  • #10 / Jul 30, 2008 1:27pm

    Bramme

    574 posts

    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?

  • #11 / Jul 30, 2008 3:10pm

    Colin Williams

    2601 posts

    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.

  • #12 / Jul 30, 2008 3:12pm

    Colin Williams

    2601 posts

    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.

    That is a really good point. I’m going to consider a different method name for that.

  • #13 / Jul 30, 2008 6:08pm

    Bramme

    574 posts

    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.

    Hmm, true, I could leave out the footer in my case, since it’s just static HTML, however, I build my navigation with the help of an array I set in the construct, that way it’s easy to create a css based navigation with hovers and an “active link” state.


    Edit: I found a bug. If you set $config[‘compress_output’] to TRUE in your config file, Firefox throws an error: I get a warning it can’t display the page because there’s smth wrong with the compression. Conflicting caching maybe?

    Well, maybe it’s not a bug, maybe it’s just a given fact, but then it should be documented 😉

  • #14 / Jul 30, 2008 6:56pm

    Colin Williams

    2601 posts

    however, I build my navigation with the help of an array I set in the construct, that way it’s easy to create a css based navigation with hovers and an “active link” state.

    You could have a $menu region that gets written to in the constructor.

    If you set $config[’compress_output’] to TRUE in your config file, Firefox throws an error: I get a warning it can’t display the page because there’s smth wrong with the compression. Conflicting caching maybe?

    For one, there should be no $config items in config/template.php. And it’s not a caching issue, it’s a gzip compression issue. Template is just an interface to Views. It does nothing to rewrite CI’s output procedures. Check to see if compression works without using Template. I have a feeling it could be a problem with your servers gzip library.

  • #15 / Jul 30, 2008 7:05pm

    Colin Williams

    2601 posts

    Okay, after some quick testing, I can ensure Template does not affect output compression nor caching. whew!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases