@634

Smarty - HelloWorld

Advertisement

helloworld

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');
?>
手順は以下の通り。
  1. Smartyオブジェクトをインスタンス化する(new Smarty)
  2. 値を設定する(assign)
  3. 表示する(display)
実行結果
helloworld実行結果
テンプレートの{$title}{$body}に対してそれぞれ値が設定された。

Advertisement

ショートカット

634
634ブログ
このカテゴリのトップページに戻る
Incubator(Pukiwiki)
634ラボ
   UIコレクションギャラリー
   ZO-3ジェネレーター

サイト検索


Y!ログール