0

I'm new to Drupal, and have stumbled across this issue. I have entries (entry) that are blogs held inside a blog_listing. E.g.

{% for entry in content.field_blog_listing_entries|field_target_entity %}
    <h2>{{ entry.title.value }}</h2>
    <p>{{ entry.field_blog_excerpt.value }}</p>
{% endfor %}

The blogs are their own entries that have automatically generated URLs. e.g. Blog 1 can be found on blogs/blog-1.

How do I get this URL from within the code block above?

I want to access the value in the same manner that I do with the title and field_blog_excerpt to put into an anchor tag. I've tried the same method e.g. entry.url.value & entry.field_blog_url.value but these don't return anything.

How do I access this URL value? Any help appreciated.

1 Answer 1

0

You can use path function with the route for node (entity.node.canonical) and the entry.id (node id) for your blog entry. Pass the id in with the "node" parameter.

<a href="{{ path('entity.node.canonical', {'node': entry.id}) }}"></a>

More info here: https://www.drupal.org/docs/theming-drupal/twig-in-drupal/functions-in-twig-templates

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.