Move template trimming to `renderTemplate`, cache trim function.