EllisLab text mark
Advanced Search
1 of 2
1
   
Template Library Version 1.3
Posted: 16 August 2008 08:28 PM
Avatar
Joined: 2006-07-27
2617 posts

Template Library Version 1.3 has been released. Version 1.3 adds new features for working with template parsers like Smarty.

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

Visit the Template Library Homepage

View the Change Log

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

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

What’s New in Version 1.3?

Since Version 1.1, Template provided the parse_view() method, allowing programmers to utilize CI’s Template Parser class when writing to regions instead of just using standard PHP-coded Views. Version 1.3 expands this functionality, allowing the use of any additional template parser, like the popular Smarty Template Engine. Along these same lines, Version 1.3 allows the master template file to be parsed by any parser class instead of always being loaded as a View.

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

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: 17 August 2008 02:26 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2008-03-27
153 posts

I love the idea of defining regions like Template does, but I noticed that it requires putting a master template into the config file. I’m developing an application where I need to be able to define the master template on the fly though. Any ideas how I might do that using something like Template?

 
Posted: 17 August 2008 02:46 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2939 posts

@AgentPhoenix, Check out View Object (see my signature) it allows regions and sub-regions also. (there is a PHP4 version)

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 17 August 2008 02:56 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Any ideas how I might do that using something like Template?

There is an add_template() method and set_template() method for this very instance, AgentPhoenix. Both are covered in the docs at:

http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html#manipulation

Essentially you do:

$new_template = array(
   
'template' => 'other_template.php',
   
'regions' => array('region1''region2''region3')
);
$this->template->add_template('name_it'$new_templateTRUE); 

Or, you can define more templates in the config file and do $this->template->set_template(‘name’);

Let me know if you need more info.

 Signature 

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

 
Posted: 17 August 2008 03:10 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2008-03-27
153 posts

Yeah, I saw the add_template() method, but for my app, I’m not a fan of having to do that in every constructor like that. I’d rather set the regions in the config file then set the master template on the fly (it’s based primarily on session variables and the like). Because of the fact that themes can be added to the application too, I’d like to avoid having users have to add a ton of stuff to the config file every single time they add a theme to the application.

Does that make sense or is the sleep deprivation going to my head? wink

 
Posted: 17 August 2008 03:14 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Ah.. just do:

$this->template->master 'other_template';
// Does not need file extension unless it is other than '.php' 

It is a bit hackish, sure, but there is currently no specific method for this action (there was in a previous release). If you’d like, I’ll add a set_master_template() method and release it for you.

 Signature 

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

 
Posted: 17 August 2008 10:17 AM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-06-06
120 posts

Well thank you very much Colin. I’ll be playing with the update over the next few days and get back to you smile

 Signature 

Milos Dakic

 
Posted: 17 August 2008 12:08 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2008-03-27
153 posts

So I can do the $this->template->master in each constructor? What do I put in the config file then? Having a method to set the master template would be awesome! Love the work you’ve done here, Colin. smile

 
Posted: 17 August 2008 04:27 PM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

That’s right, AgentPhoenix. You can do it in every constructor to set it up for the respective controller. And if it happens across all controllers, perhaps do it in a post_controller_constructor hook. In the config file, just set $template[‘default’][‘template’] to something that will satisfy the initialize() method and not throw an error… like, just a default template, even if it’s a blank file, or better yet, a file with instructions for programmers to write their own template.

 Signature 

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

 
Posted: 17 August 2008 09:13 PM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Template Version 1.4 has been released.

 Signature 

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

 
Posted: 11 September 2008 12:43 AM   [ # 10 ]   [ Rating: 0 ]
Joined: 2008-08-14
1 posts

How i can implement paging using Template library?

Thanks..!!!!

 
Posted: 19 September 2008 09:11 AM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2007-08-07
226 posts

I read through the docs (well skimmed on my lunch break) and this looks just what I was looking for coming from being familar with Zend Layout.

I have installed and set up Matchbox on my CI Demo and wondering if there is anything I need to change or be aware of when setting up a master template to use with module views?

Thanks

 Signature 

Portfolio: Portfolio
Twitter: @gunkdesign

 
Posted: 19 September 2008 10:23 AM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-06
918 posts

hey, well, the first thing you’ll want to do is get off this old thread and get on to the new one:

http://ellislab.com/forums/viewthread/88452/

 Signature 

peeker email (imap/pop) | site_migrate | OOCalendar | PhotoBox2 | word_limiter

 
Posted: 02 October 2008 03:08 AM   [ # 13 ]   [ Rating: 0 ]
Joined: 2007-11-25
46 posts

@Colin Cool…..Great stuff!

Q) With this lib, is it possible to call controllers from view? ex; If I want to call list_latest_post() on side bar of my template for every page?

Also, it would be grate if you could compile documentations into a download package.

 
Posted: 02 October 2008 10:42 AM   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-06
918 posts

hi tony… it would be better for you to post your message to the template library version 1.4 thread. wink this thread has been dead since August 17th, 2008 - see previous posts for link to new thread.

 Signature 

peeker email (imap/pop) | site_migrate | OOCalendar | PhotoBox2 | word_limiter

 
Posted: 01 November 2008 02:55 AM   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-28
10 posts

Hi, I have been reading the users guide given in

http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html

It is very good, however I am unable to test them due to the following reasons, I would request Colin Williams to look into this issue,

I have 2 issues,

My reference is with respect to the following code in the user manul.

1) Issue 1

class Page extends Controller {

function Page()
{
parent::Controller();
}
 
  function index()
  {
// Write to $title
$this->template->write('title', 'Welcome to the Template Library Docs!');

// Write to $content
$this->template->write_view(‘content’, ‘post’);
   
    // Write to $sidebar
    $this->template->write_view(‘sidebar’, ‘common/sidebar’);
   
    // Render the template
    $this->template->render();
  }

Take a look at the bold items in Blue color, this command is expecting me to have a post.php in the views folder, however this file is neither present in the template download nor described in the user manual. The same case is with respect to common/sidebar.php.

2) Issue 2

My output does not have colors / borders as given in the user guide, is there any css file I need to keep? or is there anything else I am missing?

I would appreciate if some one can help me to address the above.

Regards
Narayanan

 
1 of 2
1