doufei4923
2016-03-29 15:59
浏览 173
已采纳

在Smarty模板中显示基于数组变量的字符串

Hi all want to display the role of user hers is my code

if (isset($_SESSION['loggeduser_id']) && $_SESSION['loggeduser_id'] > 0)  {
$loggeduser_id = $_SESSION['loggeduser_id'];
}
if ($loggeduser_id > 0) {

$user = new user();
$role = $user->getrole($loggeduser_id);
$smarty->assign("role",$role);
}

And when i type var_dump($role);

it show me that

array(2) {
[0]=>
string(3) "vip"
["role"]=>
string(3) "vip"
}

so i want to show a class in the profile of user in tpl page if is vip user i try to do that and it not working

{if $role eq vip}<span class="user-vip-icon"></span>{/if}

Can u help me please

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doucheng9058 2016-03-29 17:00
    已采纳

    Thank you guys for help me i have find solution i just make that

    $smarty->assign("role",$role["role"]); instead of $smarty->assign("role",$role);

    and i put that in the template {if $role eq 'vip'}<span class="user-vip-icon"></span>{/if}

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • donv29560 2016-03-29 16:18

    Assuming you have $role as an array and $role contains array("vip", "vip"); So this should work

    $role = array("vip", "vip"); // Your ROle
    if (in_array("vip", $role)) {
        echo '<span class="user-vip-icon"></span>';
    }
    

    or

    if ($role['role'] == "vip") {
        echo '<span class="user-vip-icon"></span>';
    }
    

    or Smarty Template Code

    {if $role['role'] == 'vip'}<span class="user-vip-icon"></span>{/if}
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题