Fix javascript handling for templates