I am using views to get results which can be filtered (exposed) by the user. So far so good. Now I have to (heavily) modify the end result and while I have figured out which template I need to use, I can not find a way to fetch the actual (raw) data from the view in my template so to theme it as the client likes.

What do I have to do to get the raw data in my template? If I will have to create a module for it which steps do I have to follow to do so?

Side question, is there any other way to expose filters in a page?

  • Please explain what data you need to fetch and how that is not possible to do with Views. Specific use case help a lot to understand what you want to achieve. – berliner Mar 30 '14 at 16:13
  • @berliner I have no problem fetching data with Views, that works as intended. I can not figure out how to theme my data. A solution might be to rewrite the results tho. – afarazit Mar 30 '14 at 16:52
  • You can create custom tpl view files and theme the raw data as per your wish. See Theme Information section in your view to see which tpl files you can override. – Prerit Mohan Mar 30 '14 at 17:29
  • @PreritMohan thanks, that's what I needed. mytheme_preprocess_views_views() did it :) – afarazit Mar 30 '14 at 18:20

Theming info on each views is located under 3-rd col - Advanced on the view. Last row say "Theme:Information". Click on Information. According to your needs select template name, and create file in your current theme. Then click on "Style output" for example if you choose this kind of filename, and get code for the file (copy/paste) in above created file. Type dpm($variables); after opened php tag (install devel module ofcource) This will output available data for this template. After creating file, go agayn on theme Info and click Rescan template files. Your new file will be bolded. If not, there is something wrong - start again this process. There is too many name suggestions - get the last (longest) for your type.

Example: If we have views "Latest content" with all default options, for example we can create a file views-view-unformatted--latest-content--page.tpl.php in the theme folder. Code must be (with our dpm()):


 * @file
 * Default simple view template to display a list of rows.
 * @ingroup views_templates

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
    <?php print $row; ?>
<?php endforeach; ?>

Also we may create separate view mode for node and use them in this views. This way we may theming node views in separate file according to node view. We can get entity_view_mode module for this from DO. This is not alternative to above views theming, but as addition.

There is too many variants how to theming views - this depends what we set on the current views.

  • Thank you for your answer but I have already done (as stated in my question) all of the above. My "problem" is how to manage each of the selected fields and place them in the designated area of the theme. One solution I have been told is to use the "Rewrite results". Thank you for your time. – afarazit Mar 30 '14 at 18:12
  • entity_view_mode module might also do the trick. – afarazit Mar 30 '14 at 18:15

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.