2

There are some variables like author_name in node.html.twig of Drupal 8. {{ author_name }} will print something like below:

 <div><span><span>Basic</span></span></div>

I tried using codes like below: {{ author_name.0 }} plan to print: Basic or {{ author_name|field_value }} plan to print: Basic

Above codes NOT work. How can I achieve above result?

1 Answer 1

2

For most cases How do I get the raw field value in a twig template? will do. But since here according to node.html.twig

author_name: Themed author name field.

I believe you can get the unthemed author name by using {{ node.getOwner.getDisplayName }}

1
  • 1
    I have tested for this case (get the unthemed author name): {{ node.getOwner.getDisplayName }} works; {{ node.getOwner.getDisplayName.0 }} NOT work.
    – Basic
    Commented Dec 28, 2018 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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