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

[eluser]Milos Dakic[/eluser]
[quote author="Colin Williams" date="1219541306"]Honestly, I'm not sure what's required to get method chaining to work, but I would assume a method must return a reference to the object for each method that is chainable. You would just have to make it two lines as far as I know:

Code:
$this->template->add_region('region');
$this->template->write('region', 'content');

Quote:I’m not sure if this is possible that why I made the suggestion in the previous post. To adjust the header content attribute I’d need to so something like...

Still not sure if I'm following, but you can overwrite a regions contents by passing a third param of TRUE to the write() method, like $this->template->write('region', 'content', TRUE). You can also clear out a region with $this->template->empty_region('region')[/quote]

The region's issue (?) that I'm having is with multi dimension arrays. How can I set their values? Say if I have something like:
Code:
$template['theme_name']['regions'] = array(
    'header' => array(
                        'title' => 'Title',
                        'account' => 'Anonymous'
                    ),
    'navigation' => array(
                        'selected' => 1,
                        'type' => 'classic'
                    ),
    'content' => 'Heaps of text can go here.',
    'footer' => 'Goodbye!'
);
How would I go about setting for example the 'title' in the 'header'? Or any other item that is not in the first layer?
#12

[eluser]Colin Williams[/eluser]
Simply put, regions are not multidimensional. They don't hold additional attributes like you've laid out here. Regions are just placeholders for content. That content can be generated in anyway you choose, but typically it is with Views.

If you need additional variables available to your master template that are not regions, use the tried and trusted $this->load->vars() method in CI.
#13

[eluser]Milos Dakic[/eluser]
Can $this->load->vars() be used with other template parsers other then the default CI $this->load->view() or $this->parser->parse()?
#14

[eluser]Colin Williams[/eluser]
Quote:This function takes an associative array as input and generates variables using the PHP extract function. This function produces the same result as using the second parameter of the $this->load->view() function above. The reason you might want to use this function independently is if you would like to set some global variables in the constructor of your controller and have them become available in any view file loaded from any function. You can have multiple calls to this function. The data get cached and merged into one array for conversion to variables.

Doesn't say anything specific about the Template Parser class, but certainly covers Views. I don't use template parsers ever so it's not something I've come across. Should be easy enough to check.
#15

[eluser]Milos Dakic[/eluser]
[quote author="Colin Williams" date="1219635696"]
Doesn't say anything specific about the Template Parser class, but certainly covers Views. I don't use template parsers ever so it's not something I've come across. Should be easy enough to check.[/quote]

Yeah I don't think it works. Unless I'm doing something wrong.
#16

[eluser]wiredesignz[/eluser]
$this-load->vars() extracts your array of variables into the view buffer and is only available to $this->load->view(). Whereas the CI Parser relies on a specific $data array being passed to it.

Hope this helps.
#17

[eluser]Colin Williams[/eluser]
Good to know, wiredesignz.

So, Milos, you just need to pass that data when writing the file to be parsed

Code:
$data = array('type' => 'classic', 'active' => 1);
$this->template->parse_view('region', 'parse/file', $data);
#18

[eluser]Milos Dakic[/eluser]
Thanks wiredesignz and Colin.

Could the variables be passes to Template? Would this be logical as Template is trying to keep to the CI standard as much as possible? If this is included in Template it would mean that if Template is removed from any solution and the user decides to go back to the CI standards $this->load->view() or $this->parser->parse() their solution would not need much changing.

Thanks for all the feedback. I think any suggestions will improve Template as a library.
#19

[eluser]Colin Williams[/eluser]
Keep your eye out for the next release, Milos. I think you'll like what I come up with.

I still want to address the last part of your statement and stress that Template interfaces with views and parsers, it does not act like them. It is not a replacement for either of the two items.
#20

[eluser]Milos Dakic[/eluser]
Now I like the sound of this! Smile Thanks Colin.

[quote author="Colin Williams" date="1219760706"]I still want to address the last part of your statement and stress that Template interfaces with views and parsers, it does not act like them. It is not a replacement for either of the two items.[/quote]

Sorry, I don't think I made it clear what I was trying to say. I understand it is NOT a replacement. I was trying to say that in a case where a user decides to remove Template from their solution it will be very simple for them to update their code to do so.




Theme © iAndrew 2016 - Forum software by © MyBB