0

I created a view and I'd like to wrap it with a link in a template file. I've never worked with custom template files for views, so I've no idea where to start.

How can I do this?

1 Answer 1

1

In views under advanced->theme you can see template naming conventions you can use. Copy the views-view.tpl.php to your themes templates folder and rename it to one of the suggested names in views->advanced->theme. Clear your cache and the template will be used. Now you can alter the output of the whole view.

You can also do this for the fields as a whole, or a specific field.

Mind that views has so much power through UI that you seldom need to go through themefiles.

Wrapping the views field(s) in a link can be done also by rewriting field output.

3
  • I dont think cache clear works for views. In views->advanced->theme you have to rescan templates. Only then it works, this is message: Important! When adding, removing, or renaming template files, it is necessary to make Drupal aware of the changes by making it rescan the files on your system. By clicking this button you clear Drupal's theme registry and thereby trigger this rescanning process. The highlighted templates above will then reflect the new state of your system.
    – Mantas
    Commented May 9, 2014 at 19:07
  • @MantasKaranauskas: Clearing caches worked for me, but thanks for your comment. :)
    – Jeroen
    Commented May 9, 2014 at 19:11
  • Clearing cache clears also the themeregistry.
    – Marcel
    Commented May 10, 2014 at 8:23

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.