Smartyと連想配列 -試行錯誤中-
private $condition_dat = array(
'length' => array(
'name' => '髪の長さ',
'mapping' => array(
'very_short' => 'ベリーショート',
'short' => 'ショート',
'medium' => 'ミディアム',
'long' => 'ロング',
),
),
'weight' => array(
'name' => '髪の太さ',
'mapping' => array(
3 => '太い',
2 => '普通',
1 => '細い',
),
),
'volume' => array(
'name' => '髪の量',
'mapping' => array(
3 => '多い',
2 => '普通',
1 => '少ない',
),
'hardness' => array(
'name' => '髪の硬さ',
'mapping' => array(
3 => '硬い',
2 => '普通',
1 => '軟らかい'
),
),
),
'unruly' => array(
'name' => 'くせ',
'mapping' => array(
3 => '強い',
2 => '少し',
1 => 'ない',
),
),
'damage' => array(
'name' => 'ダメージ',
'mapping' => array(
3 => 'ある',
2 => '少し',
1 => 'ない',
),
),
);
$report = array(
'weight' => 1
)
こんな配列があって、
テンプレート側で
{foreach from=$conditions key=condition_type item=condition_values}
{if !empty($report.$condition_type)}
{$condition_values.name} : {$condition_values.mapping[`$report.$condition_type`]}<br />
{/if}
{/foreach}
こんな感じで使おうとすると
Fatal error: Smarty error: [in index.tpl line 55]: syntax error: unrecognized tag: $condition_values.mapping[`$report.$condition_type`] (Smarty_Compiler.class.php, line 446)
って出る。。うーん、よくわからない、、
`をつけたり.でつないだりやってもうまくいかない
どうやるんだろ
.…
tnx!!…