I have a view called course_programs that when I view it with Themer Info I see that it is using page.tpl.php as its page template. How do I change or supercede that? e.g. page-views-view--VIEWNAME.tpl.php and I can control the entire page?

Thanks MS

Comments

nevets’s picture

Your view will have a path so you can use that. For example if your path was 'bike', you would use page-bike.tpl.php. If your path was 'bike/three_wheel' you could use page-bike-three_wheel.php.php.

msteudel’s picture

But for some reason it's not working. It works for other pages, but they aren't views, so I thought maybe it was something related to a view. Any thoughts on what to try? I've made sure to hit the "Scan Templates" button to rebuild the registry everytime I've made a change.

nevets’s picture

Visit Administer › Site configuration › Performance, click the "Clear cached data" button (toward the bottom).

Still not working, make sure you have the file name correct (yes, I have mistyped the name). Make sure the case matches and so does the punctuation. I have a bad habit of when the view has a underscore of using a dash in the file name. For example if the view path is some_view, the template file should be page-some_view.tpl.php.

msteudel’s picture

Ok so looking at my view, and then clicking on the page section:
Path: programs/list

So my template should be:

page-programs-list.tpl.php (i cut and pasted from my filename)

Right? Then I cleared chache and rescanned my templates ... this is so bizare ...

msteudel’s picture

Ok in my template file (based of zen) I have this function:

function passagesnw_preprocess_page(&$vars, $hook) {
//$vars['sample_variable'] = t('Lorem ipsum.');
if (module_exists('path')) {

$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));

if ($alias != $_GET['q']) {
$suggestions = array();
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '-' . $path_part;
$suggestions[] = $template_filename;
}
}
$vars['template_files'] = $suggestions;
mail( 'msteudel@gmail.com', 'suggestions', $suggestions );
}
}

When I mail myself the $aliase and $_GET['q'] variable they are are the same

programs/list
programs/list

Looking at the code, it's ignoring not suggesting any template files because the alias and the $_GET['q'] are the same. If I print out the var variable the template_files is blank as well. If I take out the if statement it works. I wonder if I got this function somewhere else. It's not what is in the zen template.php file ... any ideas?

nevets’s picture

Try changing $suggestions = array(); to

$suggestions = empty($vars['template_files']) ? array() : $vars['template_files'];

to maintain any current suggestions (that code is meant to add suggestions if the page has an alias). As is this line $vars['template_files'] = $suggestions; should be inside the 'if' statement. With it's current placement it removes all template suggestions in the case the path is not aliased ($alias == $_GET['q']).

msteudel’s picture

Great idea thanks