Reputation: 505
How do I add a specific javascript to a specific node in drupal 7? Right now i add my .js javascript via the "javascript librairies" module. But this adds the .js to all nodes. I want to have myjavascript1.js enabled for node 1 and myjavascript2.je available for node 2?
Is there a way to acheive that? DO I have to make my own module?
Upvotes: 5
Views: 1494
Reputation: 19267
You can use https://drupal.org/project/scriptfield (shameless self promotion happening here). This will let you do exactly what you need, on a per-node basis.
It's most useful if you need to do it to more than one node, since it will let you do it without creating one template per node id.
Upvotes: 0
Reputation: 362
Create node--525.tpl.php
a separate template file, replace 525 with your node id and then add the javascript in the head section.
In template file add this code
<?php
function YOURTHEME-NAME_preprocess_page(&$vars, $hook) {
if ((arg(0) == 'node') && (arg(1) == 'add' && arg(2) == 'CONTENT-TYPE')) {
$vars['template_files'][] = 'page-node-add-CONTENT-TYPE';
}
}
?>
Upvotes: 1
Reputation: 31
You can create node--[nid].tpl.php file for specific node id and after that you can use your specific js file for specific node id.
Upvotes: 1