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.

Template Library Version 1.2.1

August 08, 2008 3:38am

Subscribe [11]
  • #1 / Aug 08, 2008 3:38am

    Colin Williams

    2601 posts

    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.

  • #2 / Aug 08, 2008 2:05pm

    Rick Jolly

    729 posts

    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);
  • #3 / Aug 08, 2008 4:09pm

    Colin Williams

    2601 posts

    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.

  • #4 / Aug 08, 2008 5:12pm

    Colin Williams

    2601 posts

    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.

  • #5 / Aug 08, 2008 6:08pm

    stuffradio

    378 posts

    I might check it out 😉

  • #6 / Aug 09, 2008 9:24am

    sikkle

    325 posts

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

  • #7 / Aug 11, 2008 6:05am

    Milos Dakic

    114 posts

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

  • #8 / Aug 11, 2008 6:36am

    steel_slasher

    31 posts

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

  • #9 / Aug 11, 2008 6:38am

    Colin Williams

    2601 posts

    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.)

  • #10 / Aug 11, 2008 6:41am

    Colin Williams

    2601 posts

    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.

  • #11 / Aug 11, 2008 6:46am

    Milos Dakic

    114 posts

    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?

  • #12 / Aug 11, 2008 6:58am

    Colin Williams

    2601 posts

    were you looking at adding support for Smarty in this? Or how hard would be be to add support for Smarty?

    Not anything I had considered. Template is currently only a compliment and interface to CI, so it can do only what CI can do at a low level. I also don’t particularly like or use templating languages like Smarty, and I only interfaced with the Template Parser class because it was dead easy to do. If you point me at a good Smarty parser and propose an API for it within Template ($this->template->write_smarty() maybe?), I’d be more than happy to implement it.

    Alternatively, you can just parse Smarty separately from Template and write the results with Template:

    $text = parse_smarty('smarty_file.php', $data);
    $this->template->write('content', $text);

    Your master template would still need to be PHP (couldn’t even be Template Parser syntax.. something I will address in the next release)

    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?

    The CodeIgniter License prohibits Template from being licensed on its own (because it relies on the CI codebase). So, you are only bound by the CodeIgniter license when using Template. Have at it.

  • #13 / Aug 11, 2008 7:17am

    Milos Dakic

    114 posts

    Not anything I had considered. Template is currently only a compliment and interface to CI, so it can do only what CI can do at a low level. I also don’t particularly like or use templating languages like Smarty, and I only interfaced with the Template Parser class because it was dead easy to do. If you point me at a good Smarty parser and propose an API for it within Template ($this->template->write_smarty() maybe?), I’d be more than happy to implement it.

    Maybe that isn’t such a bad idea. Got an idea of how it could be done.
    Config file:

    $config['parser'] = 1;
    /* 0 being CI templates, 1 being Smarty. */

    For the reason that, when implementing and looking to introduce Smarty into your library it wouldn’t take long as it could be all done from one function which defines the settings or methods that need to be called. Or even your end result depending on the config file.

    Don’t know if this makes any sense but I guess I’ll find out soon. 😊

  • #14 / Aug 11, 2008 7:26am

    Colin Williams

    2601 posts

    Yep, Milos, already heading that route. There are already two parsers, PHP (Views) and CI’s Template Parser class. It’s just a matter of implementing more. I’ll let you know when I have a more concrete idea.

  • #15 / Aug 11, 2008 7:32am

    Milos Dakic

    114 posts

    Great! Let me know if you need help testing or anything else.

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

ExpressionEngine News!

#eecms, #events, #releases