文字列を連結(cat)
広告
「cat」は文字列にパラメータで指定した文字列を連結します。書式は次の通りです。
{$変数名|cat[:連結する文字列]}
1番目のパラメータに連結したい文字列を指定して下さい。
具体的には次のように記述します。
{$var|cat:' and lemon'}
サンプルプログラム
では簡単なサンプルプログラムを作成して試してみます。
<?php require_once('Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = 'd:/smartysample/modifier/templates/'; $smarty->compile_dir = 'd:/smartysample/modifier/templates_c/'; $smarty->config_dir = 'd:/smartysample/modifier/configs/'; $smarty->cache_dir = 'd:/smartysample/modifier/cache/'; $smarty->assign('title', '修飾子のテスト'); $smarty->assign('msg', 'I like orange'); $smarty->display('sample19-1.tpl'); ?>
上記を「sample19-1.php」の名前で「(Apacheドキュメントルート)¥smarty¥modifier」に保存します。
{* Smarty modifier/sample19-1.tpl *} <html> <head> <title>Smarty Test</title> </head> <body> <h1>{$title}</h1> <p>{$msg|cat:' and lemon'}</p> </body> </html>
上記を「sample19-1.tpl」の名前で「D:¥smartysample¥modifier¥templates」に保存します。
そしてブラウザから「http://localhost/smarty/modifier/sample19-1.php」へアクセスして下さい。
( Written by Tatsuo Ikura )