Auto template detection