sample
$ mkdir sample
$ cd sample
composer.json
{
"require": {
"smarty/smarty": "dev-trunk"
}
}
$ curl -sS https://getcomposer.org/installer | phps
$ php composer.phar install
<?php
require './vendor/autoload.php';
$smarty = new Smarty();
class Foo {
private $str;
function set_bar() {
$this->str .= "bar";
return $this;
}
function bar() {
return $this->str;
}
}
$smarty->assign('foo',new Foo);
$smarty->assign('name','Ned');
$smarty->display('index.tpl');
$smarty->debugging = true;
$ mkdir templates
templates/index.tpl
<html lang="ja">
<head>
<meta charset="UTF-8"/>
<title>smarty</title>
</head>
<body>
{include file="contents.tpl" title="contents.tpl"}
</body>
</html>
templates/contents.tpl
<h1>{$title}</h1>
Hello {$name}, welcome to Smarty!
<p>
{$foo->set_bar()->bar()}
</p>
{for $x = 1; $x < 11; $x++}
{$x * 10}
{/for}
<br />
{* 10 20 30 40 50 60 70 80 90 100 *}
{$fruits = array('red', 'yellow', 'green', 'blue')}
<ul>
{foreach $fruits as $fruit}
<li>
{$fruit@key}: {$fruit}
{if $fruit@first} (First){/if}
{if $fruit@last} (Last){/if}
</li>
{/foreach}
</ul>
{*
0: red (First)
1: yellow
2: green
3: blue (Last)
*}