-2

I have to implement my custom markup in a view. How I can override the markup for the views header, footer, and attachments? Which TPL files I have to modify and how will be its machine names. Which also respects keeping the templates of the other views unchangeched.

2 Answers 2

1

If you have a view called foobar than you can create this tpl file in your templates/views directory:

views-view--foobar.tpl.php

Then change foobar to whatever your view is called and then clear the cache.

To create custom variables to your view create a hook_preprocess_views_view in your template.php file, like this:

function template_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  $vars['foobar'] = 'Hello World';
}

Now you have a $foobar variable in your template.

7
  • its okay but where i can find code of my view 'variables etc' to print in my tpl Sep 20, 2017 at 6:55
  • You shall put that in a preproces hook in your template.php file there are lots of tutorials on the web😀
    – user72672
    Sep 20, 2017 at 7:07
  • Did you find something useful if not I can write an answer later😀
    – user72672
    Sep 20, 2017 at 7:25
  • not i have not fond something useful.. Sep 20, 2017 at 7:32
  • I have updated my code and now it shall work.
    – user72672
    Sep 20, 2017 at 13:06
-1

To override a view you need to write three template files. Below are the files:

  1. views-view--search-page.html
  2. views-view-unformatted--search-page.html
  3. views-view-fields--search-page.html

To know exact names of template files, you can even use Devel module to find out the suggested names.

Location of these files will be : \themes\bootstrap\templates\views\ [place-your-files-here]

After you create your files, clear drupal cache for the code in twigs to be reflected.

2
  • There is no bootstrap theme installed in my site. Sep 20, 2017 at 7:34
  • You can place the template files in whatever theme you are using for your project. \themes\ [your-theme]\templates\views\ [place-your-files-here] Sep 20, 2017 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.