Welcome Guest, Not a member yet? Register   Sign In
Master templating with CI
#11

[eluser]JayTee[/eluser]
[quote author="Armchair Samurai" date="1233749409"]While template libraries are nice, I find they are often overkill for many projects.[/quote]
I'd have to disagree (slightly) on this assertion. In the case of the OP, he didn't want to put $this->load->view('whatever') in every single controller. If they are the same all the time, the template library suggested as a response is perfect. I prefer "views within views" myself; but I really hate calling CI functions within the view itself:
Bad idea:
Code:
<body>
<?php echo $this->load->view('view_name') ?>
<?php echo $this->load->view('another_view') ?>
</body>
The reason I don't like it is because "$this" is meaningless in the context of the view itself. "$this" only works because it happens to be in the context of codeigniter.
I prefer this:
Code:
<body>
<?php echo $content_of_view ?>
<?php echo $content_of_another_view ?>
</body>
I think this approach is better because it keeps the controller "in charge" of what gets loaded - and "$this" maintains it's scope within the controller from a readability standpoint.

The template library makes it easy to load views within views. Plus, it's VERY lightweight - so you're not adding a bunch of bulk to your code
Code:
$this->template->write_view('variable_name_in_view','path/to/view_file');
$this->template->render();

another good tutorial can be found here: http://codeigniter.com/wiki/MVC/
#12

[eluser]gyo[/eluser]
Good point JayTee, loading views directly from views it's not really "clean"; but I really found this method to fit my needs. I'm a fan of simple solutions (without sacrifing quality), and since I can't really see any scary bad thing in embedding views in views I guess it's just a matter of personal taste.

Anyway... it's just my point of view, and I'm willing to change my idea for a better one! Wink

Cheeers
#13

[eluser]JayTee[/eluser]
[quote author="suashi" date="1236628105"]Anyway... it's just my point of view, and I'm willing to change my idea for a better one! Wink[/quote]Not trying to change anyone's "view" (haha... good pun)
#14

[eluser]gyo[/eluser]
Indeed man! Wink

It's interesting to see where we can go with this discussion, because the views (...points of view) are already marked:

- If you use a Templating system (whatever it is), then the code is cleaner but with one more layer on the whole application.
- If you embed views from views then the code may be dirtier, but you gain in development speed (you don't have to learn any template engine syntax etc...) and rendering time (talking about millisecond here).

At this point I really think it's just about personal taste.

Any thoughts?
#15

[eluser]JayTee[/eluser]
[quote author="suashi" date="1236631625"]Indeed man! Wink

It's interesting to see where we can go with this discussion, because the views (...points of view) are already marked:

- If you use a Templating system (whatever it is), then the code is cleaner but with one more layer on the whole application.
- If you embed views from views then the code may be dirtier, but you gain in development speed (you don't have to learn any template engine syntax etc...) and rendering time (talking about millisecond here).

At this point I really think it's just about personal taste.

Any thoughts?[/quote]
My personal taste = cleaner code.

There's always the chance that I get hit by a bus and someone else has to maintain my application Smile
#16

[eluser]The Wizard[/eluser]
hello and sorry for reviving this issue,
IMHO view inside a view is logically more accurate because no template engine,
no matter how lightweight always skip the issue that
views inside views, IF separated inside folders, are actually more then easier to use
then any other system because a simple web-designer could modify or even add
other parts of that file in a matter of seconds, and not bother with a templating engine
AND
its fare more customizable.

i would prefer this->load->view.




Theme © iAndrew 2016 - Forum software by © MyBB