Add template support (issue #4154)