page.tpl.php allows customisation of the page layout, node.tpl.php allows customisation of nodes, node-content_my-type.php allows customisation of cck types.

my question is, can I in a similar way customise a view provided both as a page and a block?

thansk

Comments

brenda003’s picture

What about just adding some div tags in there or whatnot, and then styling it via CSS?

So in your block you cuold have


<div id="view-block">
[your code]
</div>

As far as I know there's no way to have a custom template for views..

adcworks’s picture

specifically, i was looking at a view i have of a cck type i created for news articles. the view outputs the headline, date and body on separate lines but i want the headline and date on the same line. they are in separate divs which is not great. i could float the divs with CSS to achieve this, but it would be nicer to be able to customise the view type itself to avoid messy css.

oh well.

adcworks’s picture

ok, i found that you can indeed theme views using the PHPTemplate override system. this is an example of how i themes the list view for my cck news type. i access the node value directly for the date to convert it to my own format. this will only apply to the news view as specified in the function name which is neat. more on how this is done is in the handbooks on theming.

function phptemplate_views_view_news($view, $type, $nodes) {

	$fields = _views_get_fields();
	
	foreach ($nodes as $node) {
		$item = '';
		foreach ($view->field as $field) {
			if ($field['field'] == "created") {
				$item .= 
					"<span class='created'>" . 
						date("d/m/y ", $node->node_created) . 
					"</span>";
			} else {
				$item .= 
					views_theme_field(
						"views_handle_field", 
						$field['queryname'], $fields, $field, $node, $type
					);
			}
		}
			
		$items[] = "<div class='view-item view-item-$view->name'>$item</div>\n";
	}
	
	if ($items) {
		return theme("item_list", $items);
	}
}
jeff h’s picture

Just to clarify for others, I assume you used the views theming wizard to produce the above function, provided by the views module.

This part of the views module is fantastic. It will provide you with a prewritten function similar to the above, and an example views-list-my_view_name.tpl.php file.

My question further to this is: the above works great for theming a view when it is producing a node... but how do you theme a view that is producing a block?

redvespa’s picture

I was having troubles trying to theme a view in a block when that view produced "View Type" list as the all the info was bundled in block->content and I couldn't find a way to pull it apart.

I've switched to "View Type" = Full Node and have created a override file called node-content_cck_story.tpl.php which is giving me control over that view of a CCK content type.