当前位置:Gxlcms > PHP教程 > smarty报错yntaxerror:unrecognizedtag

smarty报错yntaxerror:unrecognizedtag

时间:2021-07-01 10:21:17 帮助过:24人阅读

Fatal error: Smarty error: [in ./log_default.shtml line 92]: syntax error: unrecognized tag: $lang.type.$log_type.op_type_con[$info_v.op_type].op_types[$other_k][$info_v.$other_k] (Smarty_Compiler.class.php, line 446) in F:\work\zszw\manager\web\lib\smarty\Smarty.class.php on line 1093



回复讨论(解决方案)

$lang_template['type'] = array(
//日志名
'log_treasure' => array(
'name' => '宝藏日志',
//操作类型
'op_type' => array(
'OpenBox' => '打开宝藏',
),
//类型内容
'op_type_con' => array(
'OpenBox' => array(
//除开公用的op_timestamp,op_type,op_result,role_id,role_name之外的,但是不在json内的字段
'other_field' => array(
'type' => '类型',
),
//json数据
'json_field' => array(
'times' => '操作次数',
'cost' => '花费',
'item_list' => '奖励列表',
),
//可选字段,是否直接显示字段值,有出现在这个数组的将会对字段值进行转换
'op_types' => array(
'type' => array(
'1' => '青铜',
'2' => '黄金',
'3' => '神秘',
),
),
),
// '类型2' => array(
// '字段1' => '字段说明',
// '字段2' => '字段说明',
// //可选字段,是否直接显示字段值,有出现在这个数组的将会对字段值进行转换
// 'op_types' => array(
// '字段2' => array(
// '字段值1' => '字段值说明',
// '字段值2' => '字段值说明',
// ),
// ),
// ),
),
),
);
?>
<{if $v.other_field}>
<{foreach from=$v.other_field key=other_k item=other_v}>

<{if !empty($lang.type.$log_type.op_type_con[$info_v.op_type].op_types.$other_k)}>
<{$lang.type.$log_type.op_type_con[$info_v.op_type].op_types[$other_k][$info_v.$other_k]}>
<{else}>
<{$info_v.$other_k}>
<{/if}>

<{/foreach}>
<{/if}>
上面是一个数组配置,用于模板里面.

$lang.type.$log_type.op_type_con[$info_v.op_type].op_types.$other_k
谁跟你说可以这样写的?

这样写是没报错的,~ 报错的是下面那句, 5555
<{$lang.type.$log_type.op_type_con[$info_v.op_type].op_types[$other_k][$info_v.$other_k]}>

最最关键的是[$other_k][$info_v.$other_k]这个, 我一这样写旧报错了. 我写成[$other_k][1] [$other_k][2] [$other_k][3]\
都能调用到.

你要是想取数组的值那你可以采用循环去获取就好了,不能支持变量数组取值就换个方法。

人气教程排行