GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Showing posts with label Smarty. Show all posts
Showing posts with label Smarty. Show all posts

Wednesday, April 6, 2011

Smarty - Inheritance

To include another template file in a template file, for example you want to include footer and header
index.tpl
<html>
</head>
<title>Hello</title>
</head>
<body>
{include file="header.tpl" param="New York"}
<h1>Main Body</h1>
{include file="footer.tpl"}
</body>
</html>

What's the more powerful than this one is inheritance:
parent.tpl
<html>
<head>
<title>Hello</title>
</head>
<body>
{block name="content"}Default Content{/blcok}
</body>
</html>

child.tpl
{block name="content"}The New Content{/block}
Share/Bookmark

Smarty - Basic Syntax

Your main file is php file: index.php
Then your template file is a file that has .tpl extension
In index file, you write:
<?php
require_once('../libs/Smarty.class.php');

$smarty = new Smarty();
$smarty->assign('title', 'Personal Web Service');

$smarty->display('index.tpl');

?>

Then your tempate file, looks like:
<h1>Title: {$title}</h1>

Share/Bookmark

Smarty - Starting Up

Download Smarty template engine..
In your project directory, create 4 directories
1. cache
2. configs
3. templates - places your tempalete file here (.tpl)
5. templates_c

In your php file that need transfer data to template file, use include the smarty class file
require("../libs/Smarty.class.php");
$smarty = new Smarty();
Share/Bookmark