conditionally apply template