stdClass Object (
[test] => test
[users] => stdClass Object (
[createSave_email_subject] => - New
User Account
[createSave_email_pass] => The user
was created, and an email was sent to
them!
) )
Smarty代码:
Works:
{language->test}
Doesn't Work:
{language->users->createSave_email_subject}
{language[users]->createSave_email_subject}
{language.users->createSave_email_subject}
{language->users.createSave_email_subject}
{language->users[createSave_email_subject]}
答案 0 :(得分:2)
我使用此代码为此构建了一个测试用例:
$test = json_decode('{"test":"test","users":{"createSave_email_subject":"new user account","createSave_email_pass":"The user was created, and an email was sent to them!"}}');
$smarty->assign('testing',$test);
当var_dumped 时,$ test就是这个
object(stdClass)#8 (2) {
["test"]=>
string(4) "test"
["users"]=>
object(stdClass)#7 (2) {
["createSave_email_subject"]=>
string(16) "new user account"
["createSave_email_pass"]=>
string(52) "The user was created, and an email was sent to them!"
}
}
在我放置的tpl中
{$testing->users->createSave_email_subject}
它没有问题。这是使用Smarty 2.6.23
答案 1 :(得分:1)
你错过了美元符号,你应该使用
{$language->test}
不确定这是不是问题,因为我认为smarty不会输出你给出的语法。你的测试用例也不是很可靠,使用像
这样的东西更安全array('test' => 'worked');
其中键和值不同。通过测试,smarty可以打印密钥,你不会知道差异。
使用debug_print_var帮助识别您的问题。 e.g。
$language: {$language|@debug_print_var}
users: {$language->users|@debug_print_var}
cse_subject: {$language->users->createSave_email_subject|@debug_print_var}