LoginSignup
0
1

More than 5 years have passed since last update.

smartyの使い方(自分用メモ)

Last updated at Posted at 2018-08-08

職場で使うのでちょっと事前に動作を確認

smartyをcomposerでrequireする

composer require smarty/smarty

templateの作成

test.tpl
{* コメント *}

{* 変数 *}
{ var }

{*連想配列 *}
{marray.hoge}
{marray.huga}

php側による実装

run.php
require_once 'vendor/autoload.php';

$smarty = new Smarty();
$smarty->setTemplateDir('./templates/');

$marray = array(
  'hoge' => 'hogeです',
  'huga' => 'hugaです'
);

$smarty->assign('var', 'スマーティてす');
$smarty->assign('marray', $marray);

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

templateの結合

header.tpl
<title>hogehoge</title>
test2.tpl
{include file = 'header.tpl'}
{var}
{marray.hoge}
{marray.huga}

まあ、{include file = 'path'}を使えばおk
とを分割して使いまわす際とかに使いましょう

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1