How can integrate html template in codeigniter How can integrate html template in codeigniter codeigniter codeigniter

How can integrate html template in codeigniter


This is a very simple, very powerful way to do templates in codeigniter that is also very flexible.
http://news.dice.com/2013/02/18/how-to-build-a-to-do-app-with-codeigniter/

ignore the title, most of the lesson is about setting up templates in CI.

Note that i was first exposed to this method from a jeffrey way CI tutorial on net.tutsplus.com All of them are worth checking out: http://net.tutsplus.com/sessions/codeigniter-from-scratch/

edit -- ok this is good enough addition to post. So in the tutorial, on the template.php page, you will see

 $this->load->view($maincontent);

which is cool. but this is much better:

// load your header views $templatefolder = 'beta/'; if(isset($content01)) $this->load->view($templatefolder.$content01); if(isset($content02)) $this->load->view($templatefolder.$content02); if(isset($content03)) $this->load->view($templatefolder.$content03); // load your footer views 

so instead of calling the view "maincontent", i've put in references to $content1, $content2, etc. Because we are doing if isset none of them are required. that way you can easily send more then one view file to the template. Or none at all if you are just showing a message, etc. Also notice that we have $templatefolder - that way you can easily reuse the template file for other site templates, even with the same content.

in your controller (similar to tutorial) it would be

 $data['content01'] = 'codeigniterrawks'; $data['content02'] = 'mypetlion'; // beta template $this->load->view( 'template_beta', $data );

note how easy it is if i want to bring in those same view files into a different template

 $data['content01'] = 'codeigniterrawks'; $data['content02'] = 'mypetlion'; // alpha template $this->load->view( 'template_alpha', $data );


I ran into this exact question about a week ago, this guide really helped me:

http://net.tutsplus.com/tutorials/php/an-introduction-to-views-templating-in-codeigniter/

To do the CSS url's, I added "uri" to my libraries in config/autoload.php (so it looks like this:

$autoload['libraries'] = array('uri', 'database');)

" type="text/css" media="screen" />

the base_url function automatically return whatever the base url of your site is, ie

http://localhost/news/

with the argument appended to the end.

The reason behind this is that if/when you ever need to migrate servers, you just change the base_url in the config file and it automatically updates across all of your templates and sources.