EllisLab text mark
Advanced Search
1 of 17
1
   
Template Library Version 1.4.1
Posted: 02 November 2008 01:13 AM
Avatar
Joined: 2006-07-27
2617 posts

Template Library Version 1.4.1 has been released.

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

Visit the Template Library Homepage

View the Change Log

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

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

What’s New in Version 1.4.1?

Version 1.4.1 is mostly a maintenance release, fixing comment and documentation typos. In addition, the 1.4.1 download now ships with its documentation. And finally, the Template class was renamed to work more like a core library so you can extend/overload/replace it in your application libraries folder, among other things.

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

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

 
Posted: 02 November 2008 01:24 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2008-08-30
23 posts

Colin,

I have to say that after using your Template library the last hour or so, I really love it. It will make CI development much easier for dynamic sites. I am currently working on a website that requires CMS-like admin functionalities, and this library should help me a lot so that I can work with views much more efficiently and dynamically.

Connor

 
Posted: 04 November 2008 03:12 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-07-14
58 posts

Hello Colin

Great stuff love it :D

Just wondering if there a way to set a region’s default to a view file?

config.php

$template['default']['regions'= array(
   
'header' => array('view'=>'my_view_file')
); 

Or something similar?

 
Posted: 04 November 2008 05:03 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

That’s been requested a lot, warrennz. And although I don’t particularly like the idea, I might as well get it in place for people who do like the idea. I always suggest that you write the view to the region in either the Controller constructor, a parent controller, hook, or some other bootstrapping process.

 Signature 

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

 
Posted: 04 November 2008 07:52 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Okay.. I have “views embedding” in place for version 1.5

This new feature lets you embed views with an XML-style tag that can appear anywhere in your content:

$this->template->write('region''<view src="sidebar/login" />'

So, you could configure the content of a region to embed a view in this way. I think this opens up a lot of opportunities.

There are security implications, too. So, I’m not 100% sold yet.

 Signature 

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

 
Posted: 05 November 2008 12:17 AM   [ # 5 ]   [ Rating: 0 ]
Joined: 2007-06-19
1002 posts

Hey Colin,  I finally got around to looking at your Template Library.

I have a “will you consider” question.  You know I use ExtJS. Those of us that rely extensively on a lot of JS use many (many, many, sometimes) JS files.  We usually employ some method of concatenating all these files prior the being served out to the browser.  A lot of the time, that includes the CSS files too.  Let’s just say we like to minimize the TCP connections required by the browser.

So, will you consider a straight, no frills concentrator for JS files and CSS files?

Thanks for your consideration,

Randy

 Signature 

My new therapist is working with me every day, the third one gave up… ohh

 
Posted: 05 November 2008 12:37 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2007-06-19
1002 posts

I was thinking along the lines of something as simple as this:

//  $file array array('/assets/myFile.js','/assets/myOtherFile.js')
//  $type string 'js' OR 'css'
function _add_assets($files$type)
{
    $file 
realpath(trim($file"/"));
    foreach(
$files as $file)
    
{
        
if (is_file($file) && is_readable($file)) 
        {
            $assets[$type] 
file_get_contents($file);
        
}
    }
    
return implode(array_values($assets[$type])"\n");

thoughts?

Randy

[edit]  I suppose I hit the post button too fast.  The rest of the story would be outputting a MIME header and then sending this content as a single JS file for instance.

My hidden agenda is that I intend to cache this output and serve the cache.  But that isn’t for your Template to do.

 Signature 

My new therapist is working with me every day, the third one gave up… ohh

 
Posted: 05 November 2008 02:10 AM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Randy,

I teetered on the decision to add the js and css methods for the very reason that I knew a greater scope of functionality would be desired. And you’re dead on about it seeming to fall out of the realm of the Template class.

My recommendation at this point remains to use other compactors or asset libraries to get that desired effect, and then use one of Template’s methods to include the references to the compacted files. This is partly why I decided to use $_styles and $_scripts (note the underscores) as the ‘regions’ for Template’s add_css() and add_js() methods, respectively.

One other thing I want to do is look into the popular libraries/scripts specialize in that kind of compacting, and, like I did with parsers, make a sort of plug-in system that would manifest itself like parsers: Just some additional configuration settings.

A lot up in the air on it still..

 Signature 

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

 
Posted: 05 November 2008 02:16 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2007-06-19
1002 posts

In sync with you on this.  If anything comes to pass I’ll let you know.  Certainly don’t want you to duplicate effort.  A pluggable interface would be ideal.  With that in mind, I’m working with jsmin at the moment, that might be the JS answer.  The CSS thing is simple concat as far as I’m concerned.

Will let you know.

Thanks for the consideration.

Randy

 Signature 

My new therapist is working with me every day, the third one gave up… ohh

 
Posted: 05 November 2008 02:20 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Yeah, I do want to look into those things.. because there’s a lot that can be done to optimize JS and CSS beyond concatenating them, as you alluded to.

What I might do in the end is feel out the top JS and CSS optimizers and offer interfaces to those exclusively, or maybe a group for each.

 Signature 

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

 
Posted: 05 November 2008 04:49 AM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2008-06-06
120 posts

Colin I would also be interested in the idea of a “minifier” plug-and-play solution. Would come in most handy as the company I’m working for is looking to restructure their system, and the possibility of using CI is very high, which would include your Template library as it has a plug-and-play system that integrates Smarty.

Keep us posted please smile

 Signature 

Milos Dakic

 
Posted: 05 November 2008 04:52 AM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2008-06-06
120 posts

On another note just found this link: http://www.artofscaling.com/css-minifier/

Might be something to look into.

 Signature 

Milos Dakic

 
Posted: 05 November 2008 11:06 AM   [ # 12 ]   [ Rating: 0 ]
Joined: 2008-10-16
72 posts

Quick question for you. I really love the template library that you have but I am wondering how can I make the header and footer dynamic? I want to display certain sections in the header and footer of the page.

I dont’ want the current controller being called to render the header and footer as well. Is there a way to automatically call a certain view/controller to render header and footer?

thanks

 
Posted: 05 November 2008 02:47 PM   [ # 13 ]   [ Rating: 0 ]
Joined: 2007-06-19
1002 posts

Colin,

This time my question is directly relevant to Templating! wink

The concept of add_region() is so fundamentally brilliant, and brilliantly simple it is astounding.  That one method could allow modularity through simplicity like CI has not seen before.  I know you realize this because you’ve discussed it in so many threads.  I’ve just now grasped your vision.  So here is my next question…

Will you consider adding a parameter to add_region()?  That parameter would be $before=null if(null) then drop on the end of the stack, otherwise insert region in stack before $before.

That would provide us finer grained control over the output…and create a modularize application development environment. We don’t need HMVC if we have a simple template driver that allows us to insert content dynamically into the view.

The simplicity here makes this a very approachable solution that is easy to understand, adopt and implement.

What say you?  It’s on a hand full of LOCs.

Randy

 Signature 

My new therapist is working with me every day, the third one gave up… ohh

 
Posted: 05 November 2008 04:48 PM   [ # 14 ]   [ Rating: 0 ]
Joined: 2008-10-16
72 posts

Randy: Can you explain a bit more about add_region() function? I am not sure if i understood it after reading the documentation.

An example would be nice smile

 
Posted: 05 November 2008 06:26 PM   [ # 15 ]   [ Rating: 0 ]
Joined: 2007-06-19
1002 posts

Here’s what I was thinking…I wrote a class to over ride Colin’s class while he decides if this is something he would like to pursue.  Here is a replacement for add_region():

/**
    * Dynamically add region to the currently set template
    *
    * @access  public
    * @param   string   Name to identify the region
    * @param   array  Optional array with region defaults
    * @param   string Optional string region name to deposit this new region before in stack
    * @return  void
    */
   
   
function add_region($name$props = array(), $before null)
   
{
      
if ( ! is_array($props))
      
{
         $props 
= array();
      
}
      
if ( ! isset($this->regions[$name]))
      
{
          
if ( $before === null)
          
{
             $this
->regions[$name] $props;
          
}
          
else
          
{
             $pos 
array_search($before,array_keys($this->regions));
             
$this->regions array_merge(array_slice($this->regions,0,$pos), array( $name => $props ), array_slice($this->regions,$pos));
          
}
      }
      
else
      
{
         show_error
('The "'$name .'" region has already been defined.');
      
}
   } 

Now with this, you can dynamically add regions just like Colin has provided.  But with the additional parameter you can place the regions in the array stack relevant to where it shows up on the page. (it could be argued that with CSS this is a moot point.)

So now you could add widgets to your left panel, right panel, footer, header, banner, change you content region into a paneled region etc.  This becomes relevant when thinking about user roles and access rights.  Logically, you now can dynamically add and remove regions based upon the access rights of the person logged in.

You get the idea.

To implement this, the call would look like this:

$this->template->add_region('myNewRegion','','footer'); 

This would add a new region in output page (in the regions stack) above the footer.

Hope the explains what I meant.

Randy

 Signature 

My new therapist is working with me every day, the third one gave up… ohh

 
1 of 17
1