Score:-5

how to get url of link to content in twig?

cn flag

I just created one view block to show all my blogs in it. I am getting all fields in twig but unable to call "link to content" to current node of every blog from view block.

Any solution please help me.

I tried like below with url not working

<a class="d-inline-block" href="{{ url }}">
<h2 class="blog-head" style="color: #2d2d2d;">{{ content['#view'].field['field_blog_post_title'].value(row) }}</h2>
</a>
ru flag
Please don't re-post your question, improve the original one instead: [How to render Link to Content for any field from view block in Twig without preprocess](https://drupal.stackexchange.com/questions/310280/how-to-render-link-to-content-for-any-field-from-view-block-in-twig-without-prep)
apaderno avatar
us flag
Welcome to Drupal Answers! Asking again the same question without providing more details doesn't make it acceptable. It isn't still clear what you don't understand in achieving the described task. The question doesn't contain all the necessary details to answer it; saying *I just created one view block* doesn't say which settings the view is using.
Score:1
fr flag

Assuming that your blog is a node type and you got access to the node object in twig, you can use this

{{ path('entity.node.canonical', {'node': node.id}) }}

First argument entity.node.canonical is the route name, here to the node, the second argument {'node': node.id} contains route parameters, here the node parameter is mandatory which has to be the node id.


How to get the node object? I am making a guess here in which context you are but from the question, I think you are in a view and iterate over the rows variable, so a starter is to debug the row variable

{{ dd(row) }}
cn flag
i am getting "The website encountered an unexpected error. Please try again later." error when i use {{ path('entity.node.canonical', {'node': node.id}) }}
Matthias avatar
fr flag
@RaviGarnepally The variable node is probably undefined in your context. Please check your row variable, like mentioned above. An other approach is to define a new display mode and render the display mode in your view. Then you can override the twig file for this display mode like `node--yournodetype--yourdiplaymodename.html.twig`in this context the node variable will be defined.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.