combine views? |
[eluser]nofx[/eluser]
hi, i'm really new to CodeIgniter, so i probably have some basic question. But suppose i have the following view: main_view.php Code: <html> This is my main view which is devided into two columns. The left one is where my page content should be in and in the right column are menus. Suppose i goto the following url: http://localhost/index.php/news This loads the news controller and news has its own view called 'news_view.php'. I want to merge that view into my main_view.php (in the left column). How can i do that??
[eluser]WanWizard[/eluser]
Use a template library, like the one from Colin Williams. Works very well, and allows you to use your example as a template, then add the different content blocks by fetching view files.
[eluser]nofx[/eluser]
Thanks, i'll have a look. But at the same time i'm wondering, if this isn't possible with just CodeIgniter alone? I can't imagine that this cannot be done in an easy way with CodeIgniter...
[eluser]WanWizard[/eluser]
You'll either have to load views in your views (which is imho bad practice), or create a library that handles page templates. Which is exactly what a template library does...
[eluser]Abdul Malik Ikhsan[/eluser]
i think, you can create your own helper to handle your two step view templating for example, you create helper in ./system/application/helpers/using_template.php then, you add : Code: <?php then you can add to autoload.php Code: <?php Code: <head> and the last, you can call in controller Code: <?php
[eluser]nofx[/eluser]
Thanks, both methods worked out pretty wel! But i prefer the template lib. It does make the job a little bit easier I have another question though. I have a main view which is the main layout of my site. In the top of this view i have a main menu with the following items: Home, News, Contact. These names are stored in my database. I can get an array of the menu names by calling a method in my Model class. With a foreach loop (iterating through that array) i can easily generate the menu structure in my view file. Kinda like this: Code: <html> So far so good. But what if i wanted to add a css class 'active' to the link of the page that we are currently viewing. How can i do that? I could do something like this: $thispage is set in the controller Code: <html> But i'm not sure if this is the most elegant way to do it. Any idea how to improve this? Maybe by using the template library?
[eluser]Abdul Malik Ikhsan[/eluser]
first, you can use your own controller like : Code: MY_Controller extends Controller () Code: Controller extends Controller () Code: <?php // you can use inline if :)
|
Welcome Guest, Not a member yet? Register Sign In |