Moved Javascript snippet into template