PHPのお勉強



Smartyでifを利用@PHP

Smartyでifを利用します。
利用方法は、以下を参照してください。

test.php

<?php

//Smartyライブラリ
require '../libs/Smarty.class.php';

//生成
$smarty = new Smarty;

//変数「str」に、文字列「a」を格納
$smarty->assign("str", "a");

//テンプレート「test.tbl」を呼び出して表示
$smarty->display('test.tpl');

?>


test.tbl

<html>
<head>
</head>

<body>
    
{if $str == "a"}
    aです。
{elseif $str == "b"}
    bです。
{else}
    aでもbでもありません。
{/if}

</body>
</html>




Copyright (C) PHPのお勉強. All Rights Reserved.