This question involves the Zikula CMS. Is it possible to detect if a viewer is logged in and is a member of a specific group using twig? I would like to have some control code that doesn't show ad blocks if a user is a paying subscriber (is a member of a specific group). Thanks!
Asked
Active
Viewed 50 times
0
-
its symfony based try to write {{ dump() }} to show what you get on your view – episch Jun 05 '19 at 19:27
-
Thanks I will try that. – Timothy Paustian Jun 05 '19 at 20:13
-
if you switch to `dev` mode you will get more reasonable output from `{{ dump() }}` – craigh Jun 06 '19 at 00:23
1 Answers
1
For most checks like this you won't check for group memberships, but for permissions which are granted by them. So you could for example add a condition like the following to your Twig template:
{% if currentUser.loggedIn and hasPermission('MyComponent::', '.*', ACCESS_READ) %}
special block for paying members
{% else %}
show ad
{% endif %}
Note that MyComponent
can be anything, it is not limited to components used/provided by your installed extensions.
You can read more about the currentUser
global variable here.

Guite
- 203
- 1
- 2
- 11