0

I need to add following kind of java script and html element in one of my computer programe coding tutorial article:

what I want to add a java script + html to create a text box to add function to copy the text inside the box on mouse click. (I know the code and html for that, but I was unable to paste that here)

I am looking to do it through: content tab in administrative tab: add content: article: new article creation form in full html option.

Please let me know how to do it in drupal 7: by article or blog creation form or if there is any other easy way to do it.

Thanks.

1 Answer 1

0

You can add javascript in template file using hook_preprocess_page() function.

<?php
function mythemename_preprocess_page(&$vars, $hook) {
  if(arg(0) === 'node' && arg(1) === 'add' && arg(2) === 'article') {
    drupal_add_js(path_to_theme().'/js/events.js');
  }
}
?>

Other solution is that you can use theme function.

function theme_content_type_node_form($form) {
  drupal_add_js(...);
  return theme('node_form', $form);
}

This just calls the default theme function for the node add form after adding the js. As the theme function is called even the form is cached, this works nicely. You also need to implement hook_theme to make this work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.