Apply template naming logic