简体   繁体   中英

Show block depending on user group in volt, phalcon

I'm in process of learning the Phalcon framework and for this period i have had one question. How can i show an block depending on user group in .volt template? In my template engine i could write something like this:

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

I read about ACL component of Phalcon, but i want show user-group content in templates file.

You can do this with {% if %} blocks. Assume that you have the name of the group in a user object.

Controller

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

View

{% 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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM