PHP Smarty

設定

ライブラリ

https://www.smarty.net/

é…ç½®

ライブラリ
smarty-X.X.X
 └demo
 └libs
  └Smarty.class.php
  └他
コンパイルファイルé…置場所
compile
テンプレートファイルé…置場所
template
 └test.tpl

テンプレート

※test.tpl
<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>~</title>
</head>
<body>
 埋ã‚è¾¼ã¿ç”¨å¤‰æ•°
 <p>{$val1}</p>
 <p>{$val2}</p>
</body>
</html>

テンプレート利用

※~.php
<?php
require_once '~/smarty-X.X.X/libs/Smarty.class.php';

$smarty = new Smarty();
テンプレートファイルé…置場所指定
$smarty->template_dir = '~/template';
コンパイルファイルé…置場所指定
$smarty->compile_dir = '~/compile';

テンプレートファイルã®å¤‰æ•°ã¸å€¤ã‚’埋ã‚è¾¼ã¿
$smarty->assign('val1', 999);
$smarty->assign('val2', 'aaa');
æç”»
$smarty->display('test.tpl');

Follow me!