I have developed a custom template for a node where I wanted to essentially show the node in a blank white page. I created a file called node--results.tpl.php and page--node--results.tpl.php that removed just about everything except a few divs. In my module, I have function called results_view_preprocess_node
that adds the custom javascripts and css files I needed and removed.
function results_view_preprocess_node(&$variables) {
if ($variables['view_mode'] == 'full') {
$node = &$variables['node'];
if ($node->type == 'results') {
//remove all other CSS files
drupal_static_reset('drupal_add_css');
$path = drupal_get_path('module','results_view');
drupal_add_css($path . '/css/styles.css');
drupal_add_css('sites/all/libraries/jquery/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css');
drupal_add_js('/sites/all/libraries/jquery/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js');
$id = $variables['nid'];
drupal_add_js(
'meetdir="/files/results/' . $id .'";',
array(
'type' => 'inline',
'scope' => 'header',
'weight' => 5,
'group' => JS_LIBRARY,
)
);
drupal_add_js(
array(
'results_view' => array(
'path' => drupal_get_path('module','results_view'),
),
),
'setting'
);
drupal_add_js(
$path . '/js/advancedResults.js',
array(
'type' => 'file',
'scope' => 'header',
'group' => JS_LIBRARY,
)
);
drupal_add_js(
$path . '/js/filter.js',
array(
'type' => 'file',
'scope' => 'header',
'group' => JS_LIBRARY,
)
);
//drupal_set_message('<pre>' . print_r($variables,true) . '</pre>','warning');
}
}
}
I've noticed that when I load a node of this type, I get a large number of warnings and have narrowed it down to drupal_static_reset('drupal_add_css');
. When I comment this line out, I don't get the warnings, but then I don't get a clean page.
Notice: Undefined index: group in drupal_sort_css_js() (line 3129 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: group in drupal_sort_css_js() (line 3129 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: group in drupal_sort_css_js() (line 3132 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: every_page in drupal_sort_css_js() (line 3139 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: every_page in drupal_sort_css_js() (line 3142 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: weight in drupal_sort_css_js() (line 3146 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: weight in drupal_sort_css_js() (line 3149 of /mysites/html/development/drupal/includes/common.inc).
Warning: uasort(): Array was modified by the user comparison function in drupal_get_css() (line 3063 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_get_css() (line 3080 of /mysites/html/development/drupal/includes/common.inc).
Warning: ksort() expects parameter 1 to be array, null given in drupal_group_css() (line 3206 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_group_css() (line 3218 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined variable: group_keys in drupal_group_css() (line 3238 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_aggregate_css() (line 3279 of /mysites/html/development/drupal/includes/common.inc).
Notice: Undefined index: type in drupal_pre_render_styles() (line 3399 of /mysites/html/development/drupal/includes/common.inc).
As far as I have been able to tell, this is the technique you're supposed to use to create a separate template for a node, but obviously, I'm missing something. What do I need to do to fix this?
EDIT
Looking at the rendered HTML, both CSS files I add using drupal_add_css
are linked like this:
<style type="text/css" media="all">
@import url("http://www.oregonswimming.org/sites/all/modules/results_view/css/styles.css?ngdwh6");
@import url("http://www.example.com/sites/all/libraries/jquery/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css?ngdwh6");
@import url("http://www.example.com/modules/shortcut/shortcut.css?ngdwh6");
@import url("http://www.example.com/modules/toolbar/toolbar.css?ngdwh6");
</style>
drupal_add_css()
does add those array indexes, when they are not present. The problem is not the code you are showing.