- Issue created by @mithun-a-sridharan
- 🇧🇪Belgium dieterholvoet Brussels
If you have access to the entity (the
node
variable in node templates), you can get the co-authors withnode.co_authors.referencedEntities
. For example, you can get the display name of the first co-author withnode.co_authors.referencedEntities|first.displayName
ornode.co_authors.entity.displayName
.You can also show the co-authors in the view display and access the rendered output with
content.co_authors
in the node template. - 🇩🇪Germany mithun-a-sridharan Heidelberg
Hi Dieter,
Thanks for your responsiveness. Much appreciated!
Is there a mechanism to get all co-authors in the Twig file? The idea here is to create an authors' biography that goes after the content in the blog content type. The biography will include the co-authors' picture and a biography.
Following your inputs, I tried the following:
node.co_authors.referencedEntities and node.co_authors.referencedEntities|first.displayName
This resulted in the following error:
Twig\Sandbox\SecurityError: Calling "referencedEntities" method on a "Drupal\Core\Field\EntityReferenceFieldItemList" object is not allowed. in Drupal\Core\Template\TwigSandboxPolicy->checkMethodAllowed() (line 174 of themes/custom/rhythm/templates/node/node--nd-blog.html.twig).
This worked:
node.co_authors.entity.displayName
I'm new to Drupal, coming from the WordPress ecosystem.
Is there an alternative approach you'd recommend?
Thanks again!
Mithun A. Sridharan
- 🇧🇪Belgium dieterholvoet Brussels
You can fix the
SecurityError
by adding the following to your settings.php:$settings['twig_sandbox_allowed_methods'] = [ 'id', 'label', 'bundle', 'get', '__toString', 'toString', 'referencedEntities', ];
- Status changed to Closed: works as designed
7 months ago 8:41am 30 May 2024 - 🇩🇪Germany mithun-a-sridharan Heidelberg
@dieterholvoet,
It's been a while since I approached you with the issues.
The suggested fixes resolve the issues I was facing.
Thank you very much for your support.
Much appreciated!
Mithun A. Sridharan