ȥå   Խ ʬ Хåå ź ʣ ̾ѹ   ñ측 ǽ   إ   ǽRSS

PHP/Smarty/ץ

Last-modified: 2010-09-06 () 17:27:59 (2634d)
Top / PHP / Smarty / ץ

[PHP/Smarty]

̾ɽ

foo.php

<?php
// Smarty饤֥ɤ߹
define('SMARTY_DIR', '/usr/local/lib/smarty/');
require_once(SMARTY_DIR . 'Smarty.class.php');

// SmartyΥ󥹥󥹤
$smarty = new Smarty();

// ƥǥ쥯ȥλ
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->cache_dir = './cache/';

// å嵡ǽͭ
$smarty->caching = true;

// ƥץ졼ȤѿͤƤ
$smarty->assign('title', '̾');

$address_book = array('Ϻ', 'Ϻ');
$smarty->assign('address', $address_book);

// ƥץ졼Ȥꤷɽ
$smarty->display('foo.tpl');
?>

foo.tpl

<html lang='ja'>
<head>
<meta http-equiv='content-type' content='text/html; charset=UTF-8'>
<title>{$title|escape}</title>
</head>
<body text='black' bgcolor='white'>
{* ƥץ졼Υ *}

<!-- ȥ -->
<h1>{$title|escape}</h1>

<!-- ƥץ졼Ȥؤ -->
<div align='center'>
<ul>
	{foreach from=$address_book item=value name=loop01}
		<li>{$value|escape}</li>
	{foreachelse}
		<li>ɽǡޤ</li>
	{/foreach}
</ul>
</div>

</body>
</html>

Ϣɽ

foo.php

<?php
// Smarty饤֥ɤ߹
define('SMARTY_DIR', '/usr/local/lib/smarty/');
require_once(SMARTY_DIR . 'Smarty.class.php');

// SmartyΥ󥹥󥹤
$smarty = new Smarty();

// ƥǥ쥯ȥλ
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->cache_dir = './cache/';

// å嵡ǽͭ
$smarty->caching = true;

// ƥץ졼ȤѿͤƤ
$smarty->assign('title', '̾');

$address_book = array(
	array('name' => 'Ϻ',
		'fax' => '03-1111-1112',
		'phone' => array('03-1111-1111', '080-2222-1111'));
	array('name' => 'Ϻ',
		'fax' => '03-2222-1112',
		'phone' => array('03-2222-1111', '080-2222-1111'));
$smarty->assign('address', $address_book);

// ƥץ졼Ȥꤷɽ
$smarty->display('foo.tpl');
?>

foo.tpl

<html lang='ja'>
<head>
<meta http-equiv='content-type' content='text/html; charset=UTF-8'>
<title>{$title|escape}</title>
</head>
<body text='black' bgcolor='white'>
{* ƥץ졼Υ *}

<!-- ȥ -->
<h1>{$title|escape}</h1>

<!-- ƥץ졼Ȥؤ -->
<div align='center'>
<table border="1">
	<tr>
	{foreach from=$address_book item=row name=loop01}
		{foreach from=$row key=key item=value name=loop02}
			<th>$key|escape</th><td>{$value|escape}</td>
		{/foreach}
	{foreachelse}
		<th></th><td>ɽǡޤ</td>
	{/foreach}
	</tr>
</table>
</div>

</body>
</html>

ǡ̵ȤtableȤʤϡforeachelseȤ鷺Τ褦ifʬȽꤷޤ

{if is_array($address_book) && count($address_book) > 0)
	<table border="1">
		<tr>
		{foreach from=$address_book item=row name=loop01}
			{foreach from=$row key=key item=value name=loop02}
				<th>$key|escape</th><td>{$value|escape}</td>
			{/foreach}
		{foreachelse}
			<th></th><td></td>
		{/foreach}
		</tr>
	</table>
{else}
	ɽǡޤ
{/if}