Add JS file to a specific page on Drupal

I have a JS file that I want to add to Admin> Add content> A
specific type of content After viewing the .php template and checking the theme_preprocess_node function,
I tried to add JS via drupal_add_js (...), but did not go.
Now, I know that there is a similar question, however, my case is to add a JS file to a specific page and nothing else (better separation of JS files).

Thank.
(Drupal 6)

+3
source share
3 answers

Check drupal_add_js () in a page template that doesn't work .

, drupal_add_js() ( drupal_add_css()) , js/css . , , drupal_get_js() :

function yourThemeName_preprocess_page(&$variables) {
  // Is this a node addition page for the specific content type?
  // TODO: Adjust the content type to your needs
  // NOTE: Will only work for the node add form - if you want your js to be
  // included for edit forms as well, you need to enhance the check accordingly
  if ('node' == arg(0) && 'add' == arg(1) && 'yourContentType' == arg(2)) {
    // Add your js file as usual
    drupal_add_js('path/to/your/file.js', 'theme');
    // Ensure that the addition has any effect by repopulating the scripts variable
    $variables['scripts'] = drupal_get_js();
  }
}

. preprocess_page, preprocess_node, javascript . , - (+1).

+12

:

function your_module_name_init() {
    if(arg(0) == "some_name") {
        drupal_add_js(drupal_get_path('module', 'your_module_name') . '/your_js_file_name.js');
    }
}

- ?

+3

drupal_add_js /? .

+2

Source: https://habr.com/ru/post/1750601/


All Articles