Welcome Guest, Not a member yet? Register   Sign In
Template Library Version 1.4
#21

[eluser]m4rw3r[/eluser]
From what I can find in the code, it is not possible to set a view as default content of a region.

So I made a small addition to your lib, feel free to add it:
Code:
// in Template::add_region(), add this just before the closing bracket:
if(isset($props['view']))
{
     $this->write_view($name, $props['view']);
}

Then you can use it like this:
Code:
$template['default']['regions'] = array(
     'a_region' => array('view' => 'a/view'));
#22

[eluser]Colin Williams[/eluser]
That has been a common request, among others, so I'll probably get it into the next release.
#23

[eluser]Référencement Google[/eluser]
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?
#24

[eluser]Référencement Google[/eluser]
I've got a question.
From your user guide we can read:
Quote: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:
Code:
$data['posts'] = $this->blog->get_recent(5);
$this->template->write_view('content', 'blog/front', $data, FALSE, '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?
#25

[eluser]Colin Williams[/eluser]
I'll try to do it quick.

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

Code:
<strong>Name:</strong> &lt;?= $name ?&gt;

And here's a basic controller method:

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

The template just echoes the 'content' region:

Code:
&lt;?= $content ?&gt;

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

Quote:Name: John

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

Code:
<strong>Fancy Name:</strong> &lt;?= $name ?&gt;

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

Quote:Fancy Name: John

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

[eluser]Référencement Google[/eluser]
Ok I got it now, thanks
#27

[eluser]newsun[/eluser]
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?
#28

[eluser]newsun[/eluser]
anyone, templates from db still getting parsed?
#29

[eluser]newsun[/eluser]
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';

Code:
$view = STUFF from db including &lt;?=$IMG_URL?&gt; 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?
#30

[eluser]Colin Williams[/eluser]
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.

Quote: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.




Theme © iAndrew 2016 - Forum software by © MyBB