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
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.
-
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😀– user72672Sep 20, 2017 at 7:07
-
Did you find something useful if not I can write an answer later😀– user72672Sep 20, 2017 at 7:25
-
-
I have updated my code and now it shall work.– user72672Sep 20, 2017 at 13:06
To override a view you need to write three template files. Below are the files:
- views-view--search-page.html
- views-view-unformatted--search-page.html
- 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.
-
-
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