0

I need some custom markup for a view to show headers, footers and attachments in my own HTML markup. How can I create a .tpl file to a view.

0

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 – Shakil Ahmad Sep 20 '17 at 6:55
  • You shall put that in a preproces hook in your template.php file there are lots of tutorials on the web😀 – Jdrupal Sep 20 '17 at 7:07
  • Did you find something useful if not I can write an answer later😀 – Jdrupal Sep 20 '17 at 7:25
  • not i have not fond something useful.. – Shakil Ahmad Sep 20 '17 at 7:32
  • I have updated my code and now it shall work. – Jdrupal Sep 20 '17 at 13:06
0

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.

  • There is no bootstrap theme installed in my site. – Shakil Ahmad Sep 20 '17 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] – Pranay Agarwal Sep 20 '17 at 8:28

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.