Improve handling of custom dialog templates passed to