Better javascript in template