Smarty - HelloWorldAdvertisementhelloworld
SmartyでHelloWorldを作ってみる。
テンプレートファイル(templates/helloworld.tpl)
<html>
<head>
<title>{$title}</title>
</head>
<body>
{$body}
</body>
</html>
{$xxx}はテンプレート変数であり、プログラムの実行時に動的に値を設定するための構文。プログラム(helloworld.php)
<?php
require_once('Smarty/Smarty.class.php');
$smarty = new Smarty;
$smarty->assign("title", "sample");
$smarty->assign("body", "helloworld");
$smarty->display('helloworld.tpl');
?>
手順は以下の通り。
![]() テンプレートの{$title}{$body}に対してそれぞれ値が設定された。 Advertisement |
ショートカット・634・634ブログ ・このカテゴリのトップページに戻る ・Incubator(Pukiwiki) ・634ラボ UIコレクションギャラリー ZO-3ジェネレーター サイト検索Y!ログール |