Search code examples
drupal-7drupal-views

Drupal 7 - view theme field tpl


In D7, I have created a view and assigned this to a block (sidebar_first).
I have also created a view field tpl within the theme's template folder named - views-view-fields--categories--block.tpl.php

I want to show the name of categories (results) in an unordered list (UL / LI) HTML structure.
Can someone help me?

Following is the data when I placed the code print_r($row);

stdClass Object
(
    [taxonomy_term_data_name] => Category 1
    [taxonomy_term_data_vid] => 1
    [tid] => 1
    [taxonomy_vocabulary_machine_name] => categories
)


stdClass Object
(
    [taxonomy_term_data_name] => Category 2
    [taxonomy_term_data_vid] => 1
    [tid] => 2
    [taxonomy_vocabulary_machine_name] => categories
)

Solution

  • In the field tpl you will always get a single row, but if you create a tpl with "display output" naming convention in Theme: Information of the view you will get all rows in one array.

    You can find theming information of a particular view in its view edit page >> Advanced options >> theming information

    Choose the theme where your site is using and then choose a view template in display output section.

    And then get the code for it after clicking display output link here and copy paste it in the tpl file created.

    Now print the $rows in the view tpl, you will get all the categories in one rows array.