0

I am currently developing a website in Drupal. I have a load of news articles which are of content type 'news'. I want to create a widget to show at the bottom of several pages listing the latest articles. I have managed to achieve thus far by creating the view with the fields I want and then making the view available as a block.

The problem is the format in which the articles are being listed in the view. Ideally I would like to customise the HTML. I understand that I can create a custom template to target views/blocks but I haven't quite got a full understanding of it yet, and find the Drupal documentation to be quite dry and therefore hard to find what I need from.

Any pointers would be helpful.

diggersworld
  • 12,770
  • 24
  • 84
  • 119

1 Answers1

1

Go to your view edit page and select "table" as your view mode.

Go to "Theme information" and look for the desired (style output) template name.

Copy this name and create a new file in your theme folder using this name. I.e.: views-view-table--view-name-block.tpl.php.

In this file you can use the following structure (as an example) to get the values of the fields:

<?php foreach($rows as $row):?>
<div>
<h2><?php print $row['title'];?></h2>
<p><?php print $row['field_custom'];?></p>
</div>
<?php endforeach;?>

Don't forget press rescan theme files after you saved the file in the view theme section.

You can get as specific as you want. Create a block view next to the default or page view and you will see specific file names in the "Theme information" section.

robbierusa
  • 26
  • 2
  • I've managed to create the tpl file and get that pulled in. The `$rows` variable is NULL though, so how do I retrieve that? My template has the rather lengthy name of: `block--views--home-locations-services-block-1.tpl.php` – diggersworld Dec 05 '14 at 09:36
  • Ah I got it... should have read your answer properly. Looking at the them information gave me the knowledge. Cheers dude. – diggersworld Dec 05 '14 at 09:48