-1

I want to add in theme template . Are there any disadvantages using scripts inside a drupal template tpl.php file.?

1 Answer 1

3

It depends:

  • Is it your own theme? (sub-theme from contributed theme usually) - If not, you better not hack it. (you changes will be deleted next time you will update the theme)
  • Assumes above as yes, do you have many templates files?
  • Is it a "root" template? like html or page or is it more in depth like node, search-result and so on?

The disadvantages:

  • You must copy-paste this script to all overriding template files if template suggestions, suggest another variation of the template. (e.g page.tpl.php, page--front.tpl.php, page--node--article.tpl.php
  • You must make sure manually, this script does not appear twice in different places.
  • Take into consideration this script will go in any page users can see. (e.g search results page, taxonomy index, node pages, views pages, user login/registration pages.) - If it is not necessary in all pages, this is bad practice.
  • Performance wise, the JS aggregation feature will not work for this script, so this means one more request from the client.

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.