BerryPro : adding js scripts between <head> and </head>

Hello,
For the purpose of creating 3D card flip effects on a specific node, I added js scripts in the html.tpl.php template of BerryPro theme.
In Drupal 6, I could rename this template this way : "page-node-394.tpl.php" but it seems not to work with Drupal 7 and I should add the code in the global template "html.tpl.php".
As I intend to add other sliders, I would like to know if I can use another way than adding code always in the general file ?
Thanks in advance for your reply.

Comments

user
Submitted by admin on Sun, 12/06/2015 - 06:59

If you want to add any global (available for all pages) CSS / JS file, you can simple add in /tmplates/html.tpl.php

If you want to add a js file for a specific node only, please follow below steps.

  1. Put your new js file myscript.js in /js folder of theme.
  2. Add following codes in template.php
 
if ($node->nid == 123) {
drupal_add_js(drupal_get_path('theme', 'berrypro') . '/js/myscript.js');
}

Change 123 to node ID of your page.
Done!!!

If you want to add js file for homepage only, add below code in template.php

 
if (drupal_is_front_page()) {
drupal_add_js(drupal_get_path('theme', 'berrypro') . '/js/myscript.js');
}
user
Submitted by cococom64 on Mon, 12/07/2015 - 11:32

Thanks for your quick answer.
I am going to try these different ways of customizing header sections.

user
Submitted by cococom64 on Thu, 01/25/2018 - 17:51

Hello,
I have a problem with the solution consisting in changing the template.php and I have this error message :

Notice : Undefined variable: node dans include_once() (ligne 12 dans /var/www/drupal/hiddendossier/drupal7dev/sites/all/themes/berrypro/template.php).
Notice : Trying to get property of non-object dans include_once() (ligne 12 dans /var/www/drupal/hiddendossier/drupal7dev/sites/all/themes/berrypro/template.php).

Thank you in advance for your help.
Best regards

user
Submitted by cococom64 on Fri, 01/26/2018 - 01:38

Hello,
It seems I found the solution by writing the condition inside the function berrypro_preprocess_node(&$variables) as you can see below :

function berrypro_preprocess_node(&$variables) {
$variables['submitted'] = t('By: !username', array('!username' => $variables['name']));
if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
$variables['classes_array'][] = 'node-full';
}
$node = $variables['node'];
$comment = $variables['comment'];
$variables['submitted_day'] = format_date($node->created, 'custom', 'j');
$variables['submitted_month'] = format_date($node->created, 'custom', 'M');
$variables['submitted_year'] = format_date($node->created, 'custom', 'Y');
if ($node->nid == 6350) {
function berrypro_js_alter(&$javascript) {
$javascript['misc/jquery.js']['data'] = drupal_get_path('theme', 'berrypro') .
'/js/jquery.js';
$javascript['misc/jquery.js']['version'] = '1.10.2';
}
}
}
As I am not a developper I hope this solution is correct even if it solves my problem to display tab shortcodes for Berrypro in a specific node.
Thanks in advance for your advise.
Best regards