Part of the EllisLab Network
   
3 of 15
3
Template Library Version 1.4
Posted: 02 September 2008 02:11 PM   [ Ignore ]   [ # 21 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2774
Joined  07-27-2006

That has been a common request, among others, so I’ll probably get it into the next release.

 Signature 

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

Profile
 
 
Posted: 05 September 2008 09:50 AM   [ Ignore ]   [ # 22 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  801
Joined  04-20-2006

Hi Collin,

Very nice library here, however I have 2 requests:
- I second m4rw3r in his request to be able to load views how he explained it
- Could you include the User guide as HTML into the Zip download like CI does it?

 Signature 

Un blog seo white-hat expliquant quelques techniques intéressantes sur le seo black hat

Ionize CMS - Webdesigner CMS based on CodeIgniter
www.ionizecms.com

My website: Webagency Too Pixel

Profile
 
 
Posted: 05 September 2008 10:38 AM   [ Ignore ]   [ # 23 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  801
Joined  04-20-2006

I’ve got a question.
From your user guide we can read:

Cascading Views

A core principle of the Template library is flexibility, so the write_view() method lets you suggest other View files to load if the defualt View file you passed in the first argument doesn’t exist. To suggest other View files for Template to use, pass them discretely, starting with the 5th argument:

$data['posts'$this->blog->get_recent(5);
$this->template->write_view('content''blog/front'$dataFALSE'blog/posts'); 

If this was a blog application, using this method lets us create a View file at views/blog/front.php to format blog posts distinctly when they appear on the front page, or opt-out and let our standard views/blog/posts.php handle the output. We could suggest more fallbacks if needed in the 6th, 7th, 8th arguments, and so on.

I am not sure I understood how to manage that interesting feature and after some tests I can’t get to something working. Can you post here a full example?

 Signature 

Un blog seo white-hat expliquant quelques techniques intéressantes sur le seo black hat

Ionize CMS - Webdesigner CMS based on CodeIgniter
www.ionizecms.com

My website: Webagency Too Pixel

Profile
 
 
Posted: 05 September 2008 01:20 PM   [ Ignore ]   [ # 24 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2774
Joined  07-27-2006

I’ll try to do it quick.

Here’s a view at application/views/basic.php:

<strong>Name:</strong<?$name ?> 

And here’s a basic controller method:

function show_name()
{
   $data 
= array('name' => 'John');
   
$this->template->write('content''fancy'$data'basic');
   
$this->template->render();

The template just echoes the ‘content’ region:

<?$content ?> 

So, when we fire up this controller method, since we have a basic.php view and not a fancy.php view, we see:

Name: John

Now, lets add a view at application/views/fancy.php

<strong>Fancy Name:</strong<?$name ?> 

Now when we fire up the controller method, we should see:

Fancy Name: John

This type of cascade can be applied to a number of scenarios (opt-in template specialization, theme systems, etc)

 Signature 

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

Profile
 
 
Posted: 05 September 2008 01:25 PM   [ Ignore ]   [ # 25 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  801
Joined  04-20-2006

Ok I got it now, thanks

 Signature 

Un blog seo white-hat expliquant quelques techniques intéressantes sur le seo black hat

Ionize CMS - Webdesigner CMS based on CodeIgniter
www.ionizecms.com

My website: Webagency Too Pixel

Profile
 
 
Posted: 06 September 2008 02:47 PM   [ Ignore ]   [ # 26 ]  
Grad Student
Rank
Total Posts:  36
Joined  08-26-2008

We are trying to figure out how to load templates from a database instead of from the file system. Any ideas on how we could take a template and pass it in as a string to get parsed for data regions?

Profile
 
 
Posted: 09 September 2008 07:07 PM   [ Ignore ]   [ # 27 ]  
Grad Student
Rank
Total Posts:  36
Joined  08-26-2008

anyone, templates from db still getting parsed?

Profile
 
 
Posted: 10 September 2008 04:49 AM   [ Ignore ]   [ # 28 ]  
Grad Student
Rank
Total Posts:  36
Joined  08-26-2008

I guess my terminology was off a bit, what I meant was to add a region into a region from a db then have that 2nd one replaced, so a region within a region basically is what we wanna do.

A simple example of what we wanna do for now:

regions set
content
IMG_URL

so from a db we pull in the content which has multiple region of img_url to be replaced, it’s just that once we write the info to content, the region of img_url does not seem to exist even though it has been written to the template.
$IMG_URL = ‘someURL’;

$view STUFF from db including <?=$IMG_URL?> and some other STUFF
above line would have been pulled from a db record

$this
->template->write('content',$view);
$this->template->write('IMG_URL'$IMG_URL); 

Basically if we could do what write_view or parse_view do with a data string instead of a file.

On another note, I am wondering beyond calling in another parser, data appending or ‘Cascading Views’-view replacement based on $data array; what does this do that $this->load->view(‘master_template’, $data); does not already and $data array does not have to be defined in advance just exist on the template is a benefit to normal view calls?

Profile
 
 
Posted: 10 September 2008 06:11 AM   [ Ignore ]   [ # 29 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2774
Joined  07-27-2006

For ad hoc miniature templates like that, newsun, str_replace or preg_replace functions will probably serve you well enough. I don’t think the overhead of running a parser or loading a faux-view is worth it.

On another note, I am wondering beyond calling in another parser, data appending or ‘Cascading Views’-view replacement based on $data array; what does this do that $this->load->view(’master_template’, $data); does not already and $data array does not have to be defined in advance just exist on the template is a benefit to normal view calls?

I tried reading that left to right and went South really fast. I think you were asking how is Template different than using vanilla views. What Template does essentially is manage that $data array in a wider context than the requested controller function, and even the controller itself.

 Signature 

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

Profile
 
 
Posted: 10 September 2008 05:53 PM   [ Ignore ]   [ # 30 ]  
Grad Student
Rank
Total Posts:  36
Joined  08-26-2008

We ended up doing a str_replace in this case as mentioned and will probably just add this method into the Template library on our end as it’s something that will get used often…I think it would be minimal overhead to have a method available as part of the install and it allows more flexibility
It could simply be: parse_string or write_string, or just a boolean trigger in the write or write_view methods

Here is basically what we added:

function parse_string($string$array{
        
    
foreach ($array as $key => $value{
        $string 
str_replace('<?=$'.$key.'?>'$value$string);
    
}
        
    
return $string;
    

As to my other question, you basically answered it. What I think would beneficial would be a concise list of the additional features Template offers over built in view. I saw three main ones and that is what I listed.


Also what is the purpose of making regions manditory to be defined? Is it for speed based on the length of array which is looped through? To avoid having to search for a region in the file which might not exist, this gets done if there is a region defined anyhow, right?

Profile
 
 
   
3 of 15
3