【问题标题】:Show block depending on user group in volt, phalcon根据用户组以伏特,phalcon 显示块
【发布时间】:2015-01-14 21:43:24
【问题描述】:

我正在学习 Phalcon 框架,在此期间我有一个问题。如何根据 .volt 模板中的用户组显示块?在我的模板引擎中,我可以这样写:

[group=guest]<div>You should register</div>[/group]
[group=user]<div>Welcome!</div>[/group]

我阅读了 Phalcon 的 ACL 组件,但我想在模板文件中显示用户组内容。

【问题讨论】:

    标签: php phalcon


    【解决方案1】:

    您可以使用 {% if %} 块来执行此操作。假设您在用户对象中有组的名称。

    控制器

    ....
    $this->view->setVar('user', $user);
    ....
    

    查看

    {% if user.group == 'guest' %}
    <div>You should register</div>
    {% elseif user.group == 'user' %}
    <div>Welcome {{ user.name }}</div>
    {% else %}
    <div>You should register</div>
    {% endif %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-26
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      相关资源
      最近更新 更多