Welcome Guest, Not a member yet? Register   Sign In
Please, recommend a template solution for my needs...
#1

[eluser]knucklehead[/eluser]
Hello!
I have in mind to make a site which would consist of a header/menu/footer template, and basically, only one part of page would have to change. Each part of my page (header, footer or any other) would be some controller who is getting some data from MySQL and sending it to a specific view.
Please, recommend me some template engine/plugin/framework for what I need (of course, to fit in CodeIgniter framework).
...I have tried Template Library for CodeIgniter, but if I understand correctly, I cannot accomplish that with it? Am I right?

Thanks for any help in advance Smile
#2

[eluser]BrianDHall[/eluser]
Have you read the wiki on this subject? http://codeigniter.com/wiki/Header_and_f...very_page/

The basic is view partials - the third parameter of $this->load->view() allows you to return the content of a view instead of echoing it directly. So you load the 'view partial' into a variable - your page content - then pass that variable into your master view, or "page template".

You don't need anything other than CI itself, no need even for the template class.
#3

[eluser]2think[/eluser]
BrianDHall's solution is sensible and also he provides a very good, short explanation.

But, in the event you're looking around, Colin Williams's template library is also a very good addition. You can still use Views but it has some interesting functions that make it a bit more flexible; for example, the ability to add dynamic regions to an existing template, multiple templates, etc. He has an excellent userguide writeup and you can find more here http://ellislab.com/forums/viewthread/95687/
#4

[eluser]Colin Williams[/eluser]
Thanks, 2think, but I think he might already be trying to use my library for what he's doing.

Brian was correct in saying "You don’t need anything other than CI itself, no need even for the template class." Part of CodeIgniter's brilliance is that the Controller class is essentially the core of the application. Developers need to embrace this and look to modify the Controller class (overload it or extend it with a MY_Controller class) whenever they need things to happen "globally" or "on every page." I actually wish CI shipped with a MY_Controller class and that the docs instructed that you extend MY_Controller all the time. I don't think I've written a CI app that doesn't do this.
#5

[eluser]knucklehead[/eluser]
Thanks a lot for all of your replies!

I haven't been working with CI for a while, and some stuff just disappeared from my head... For that reason, I still have some confusion in my mind about my 'template'... I have been reading and trying to adopt Jedd's method, because it seems simple enough, and I think I won't need anything more than that. But I couldn't dig it completely...

Can you, please, tell me where am I making a mistake in my logic:

- All of my stuff (header, footer, other modules) are coming from DB, so I have few models for that... One model has many functions for getting same set of data but with different conditions (different MySQL queries).

- When I create MY_Controller class, it should serve only to get all data from my models and send that data to each of my views. I imagine this would be something like:
Code:
$this->load->model('events_model');
$event_data['events'] = $this-> events_model->get_some_events();
$this->data['some_name'] = $this->load->view('events', $events_data, TRUE);
Is this true?

- In each of my 'standard' controllers I should accept that data and send it to default view somehow? Is that right?
For example, my index function in event class should look similar to this;
Code:
$this->data['content'] = $events_data;
$this->load->view('default', $this->data);
and in some other class (let's say NEWS), my index function would look similar to this:
Code:
$this->data['content'] = $news_data;
$this->load->view('default', $this->data);

- Finally, in my default view, I am echoing $content.

Damn, I confused myself to death with this post, I hope I didn't confuse all of you so much Undecided
#6

[eluser]knucklehead[/eluser]
Ufff..
After a while I managed to understood the logic, but it was an hour of serious headache Smile
Anyways, I'm glad that it will go much easier from now on, and I would like to thank you one more time for all the help and tips!
CodeIgniter is really a great thing!! Smile
#7

[eluser]BrianDHall[/eluser]
[quote author="knucklehead" date="1261902800"]Ufff..
After a while I managed to understood the logic, but it was an hour of serious headache Smile
Anyways, I'm glad that it will go much easier from now on, and I would like to thank you one more time for all the help and tips!
CodeIgniter is really a great thing!! Smile[/quote]

One thing, if for some reason need to not have PHP inside your Views, you can then use a Template library - but it really is one more thing to learn, so it depends on your needs whether or not you really need to bother. You can always start using them later on, especially Phil Sturgeon's wrapper to make Dwoo replace the built-in Template Parser.

It's the only one I've personally tried, but I built two full projects (and rebuilt one of them) without using anything but normal CI view functionality.




Theme © iAndrew 2016 - Forum software by © MyBB