My user case is:

Extlink module can add exception classes to avoid processing some links.

I want some external url links on nodes whom author belongs to a special role (premium) can be mark with a class (for example with premium role name) to set an exception at external links module.

Well, at node twig template I can render node owner name, using this: {{ node.Owner.name.value }} but I don't know how render author roles.


You can get roles in twig using:

{%  for role in node.Owner.roles %}
    {{ role.entity.label }}
{% endfor %}

Update :
If you want to use roles in classes i recommended you to use clean_class filter to get the clean css class from roles instead of the code you post in comment use this:

   {% set custom_classes = [] %}
    {% for role in node.Owner.roles %}
      {% set class_role = role.entity.label | clean_class %}
      {% set custom_classes = custom_classes | merge([class_role]) %}
    {% endfor %}
    <div {{ attributes.addClass(custom_classes) }}>
      {{ content }}
  • Perfect, my code output is like: ` <div class=" {% for role in node.Owner.roles %} {{ role.entity.label }} {% endfor %} ">Test {{ content }} </div> ` – calbasi Jan 3 '19 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.