Put javascript in templates in right place