Header Ads

PHP Project - CodeIgniter Plus Smarty


Templating is a controversial topic with some developers since they feel that using PHP directly in the HTML is easier than learning a new templating language to accomplish the same thing. I personally like having a clean separation between code (PHP) and views (templates using Smarty). I have seen too many developers get sloppy and start adding logic and even database calls in their HTML. This can quickly become a maintenance nightmare. I also like the fact that Smarty uses different delimiters {} from HTML <>. This makes spotting the Smarty tags easy. A simple example that illustrates this point is:



Using Smarty:
<title>{$title}</title>

Using PHP:
<title><?php echo $title;?></title>

Sample controller: welcome.php
class Welcome extends CI_Controller {

public function index()
{
$data['
title'] = 'Codeigniter Plus Smarty';
$data['
content'] = 'This is sample Content';
$this->parser->parse('
welcome',$data);
}
}

Sample usage: welcome.tpl
<!DOCTYPE html>
<
html>
<
head>
<
title>{$title}</title>
</
head>
<
body>
{$content}
</
body>
</
html>

Include other template like header, navigation bar or footer:
{include file="header.tpl"}




Thank you for your visit.



Download full package here: Codeigniter 3.x and Smarty 3.x

Link:
CodeIgniter Plus Smaty

RAR Password: coloftech2017

No comments

Powered by Blogger.