0

I created a view via the administration interface. This view lists content (style teaser; title and image). The default link of titles is /node/'nid'; I want to replace the link with /custompate/'nid'.

I suppose I must "find" the template of my custom view and overwrite it in a custom module.

How can I find the name of the template for this specific view?

Edit : the "advanced" block in my view (theme information is missing :/)

enter image description here

2

One way to accomplish this would be to change the view from showing content to showing fields. You can then add the fields that you want to show, title and image.

To change the link of the title, you can add the nid as a field, hide it, and then rewrite the output of the title field to include the custom path and nid in the link.

To find the template files of the view, you need to click on the "Advanced" tab and look for "Theme: Information". You'd need a sub-theme to register the template file being overwritten. Drupal Sub-theming

To overwrite it in a module, you could use a pre render hook and modify the rows on the result fields.

  • Thanks for your answer =) I edit my first post and show the "advanced" block of my view. The "Theme : Information" is missing :/ – user2137454 Dec 6 '15 at 22:37
  • Have you tried changing the view to show fields and then rewriting the results of the title field? – Alex Finnarn Dec 6 '15 at 23:07
  • I do ! but when I want rewrite the url result, I haven't access to the node avec the item :/ No twig taf isn't proposed for get the nid – user2137454 Dec 8 '15 at 19:04
0

There are 2 aspects to the problem: 1) having the desired URL in the view for each content item; and 2) having those URLs go to the right Drupal page

The first part can be solved in the Views dialog by specify the fields you want in the view (Format>Show>Fields) and then for the Title field choose to "Rewrite results" into being a link. It's fiddly, and I imagine you'll have to use tokens, but it's a standard task and the Views docs should able to guide you through it.

The second part can be solved by modules like pathauto or redirect.

  • "Theme information" is removed in Drupal 8, use Twig debugging instead. – Jonathan Dec 7 '15 at 21:05
  • There isn't twig tag with a the title field or image field who propose the link of the node – user2137454 Dec 8 '15 at 19:05
  • Sorry, your comment is not clear to me. – Jonathan Dec 10 '15 at 15:22
0

Use this format:

views-view--[viewsMachineName]--[viewsDisplay].html.twig

for example;

views-view--articles--block.html.twig for a view named articles which display type is block.

This worked for me, hope it helps you too.

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.