Fixed #15053 -- Improved template extending algorithm.

*full path to the template source*