Posted by degeer on January 15, 2009 at 3:51pm
I'm work on a site where we are using views to display various content. Our front-end developers have been instructed to work with tpl-files that are put in our theme. They have to be able to create template files in the same manor as they do for page, node, blocks - e.g. page-node-1.tpl.php, page-node.tpl.php etc.
I've come up with a solution where I re-use code from http://api.drupal.org/api/function/template_preprocess_node/6
Views
function phptemplate_preprocess_views_view( & $vars)
{
$i = 0;
$suggestion = 'views-view';
$suggestions = array ();
while ($arg = arg($i++))
{
$suggestions[] = $suggestion.'-'.$arg;
if (!is_numeric($arg))
{
$suggestion .= '-'.$arg;
}
}
if ($suggestions)
{
$vars['template_files'] = $suggestions;
}
}Views-table
function phptemplate_preprocess_views_view_table( & $vars)
{
$i = 0;
$suggestion = 'views-view-table';
$suggestions = array ();
while ($arg = arg($i++))
{
$suggestions[] = $suggestion.'-'.$arg;
if (!is_numeric($arg))
{
$suggestion .= '-'.$arg;
}
}
if ($suggestions)
{
$vars['template_files'] = $suggestions;
}
}Questions
- Is there a better way to do this without creating these two functions in template.php?
- If there isn't a better way - shouldn't these functions be put into views core?
Comments
view templates
I recommend this tutorial:
http://mustardseedmedia.com/podcast/episode23
1. Is there a better way to
Nope.
No. It is very very confusing to mix the pattern style of alternative templates and the suggestions style. It's ok for you to do that in your theme, if you know what you're doing, but I will not be publishing a module that does it. I don't want the support requests.