I want to add in theme template . Are there any disadvantages using scripts inside a drupal template tpl.php file.?
1 Answer
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
orpage
or is it more in depth likenode
,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.