Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By kay.beissert on
I want to show custom-node-edit-links in node-teaser and nodes. But I can't check the actual access permission of the logged in user. In drupal-7-node-templates this was possible via php, but what can I do to check these permissions in Drupal 8 node-templates (via twig).
Thanks in advance
Comments
You can check for a
You can check for a permission:
This is sort of mentioned in the node template doc comments:
What it doesn't mention is the entire user object is in the $variables array, and you can use those same get, has and is methods - debugging with Devel in preprocess and you can easily discover these methods.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thank you, this sollution
Thank you, this sollution works perfect. You saved me hours of trial and error.
Hi Jeff,
Hi Jeff,
How to check a visit if logon or not?
thanks in advance.
Got it:
Got it:
alternates of haspermission
Thanks Jeff,
Can we use something similar for roles_target_id as i have multiple custom user types and need to put different conditions on based of same in TWIG file.
Could we also check IP adress range?
Thanks, this should be in de right direction for fixing my challenge.
Is it also possible to check the users ip adress and when this is in the right range a body class will be set and the frontpage is set to another location?
What I like to accomplisch is something like:
$ip = ip current user;
$iprange = 1.2.3.32/27;
{% if logged_in %} and {% if $ip <> $iprange %}
… frontpage = '/front2'
… bodyclass = 'red'
{% else %}
... do something
{% endif %}
I found this link, https://github.com/symfony/http-foundation/blob/master/IpUtils.php#L36 maybe there is already a method in the Symfony framework?
Thanks in advance.