开发者

Smarty Object Syntax

I registered an object an I'm trying to get the following below:

 stdC开发者_如何学Pythonlass 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 Code:

 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]}


I built a test case for this using this code:

$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);

$test is this when var_dumped

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!"
  }
}

In the tpl I placed

{$testing->users->createSave_email_subject}

And it worked without issue. This was using Smarty 2.6.23


You're missing the dollar signs, you should be using

{$language->test}

Not sure if that's the problem though, as I didn't think smarty would output anything with the syntax you gave. Your test case isn't very reliable either, it's safer to use something like

array('test' => 'worked');

where the key and value are different. With your test, smarty could be printing the key and you wouldn't know the difference.

Use debug_print_var to help identify your problem. e.g.

$language: {$language|@debug_print_var}
users: {$language->users|@debug_print_var}
cse_subject: {$language->users->createSave_email_subject|@debug_print_var}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜