Jump to content

HTML templates in codeigniter (Newbee)


mo

Recommended Posts

I am new to OOP but proficient in PHP. I am rewriting my website and I decided to use codeigniter as cakePHP was confusing as hell.

 

My current site is all procedural and I have a php file called main_tmpl.php which contains various variables (listed below) that I use in all my pages for the HTML formatting.

 

How can I reproduce this in codeigniter? I do not want to enter my core HTML in every view page.

 

Example variables in my main_tmpl.php file and how I use them.

$html_head = "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head>";

$html_head_end = "</head>";

$html_body_start = "<body>";

$html_body_end = "</body>";

$html_main_content = "<div id=\"main-frame\"><!--Main Frame Div:Start-->";

$html_main_content_end = "</div><!--Main Frame Div:End-->";

 

I echo these variables in my PHP pages. How can I reproduce this effect in codeignitor?

Link to comment
https://forums.phpfreaks.com/topic/184582-html-templates-in-codeigniter-newbee/
Share on other sites

You just need to nest your views:

 

$nested_view_data['title'] = 'Page Title';
$data['head'] = $this->load->view('head',$nested_view_data,TRUE);
$this->load->view('main_tmpl',$data);

 

This would assume you have a view named head, and there is a $title variable in it. This gets inserted into the main_tmpl view.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.