Fixed #15053 -- avoid recursion when extending templates

The `extends` template tag now avoids recursion, making it possible for
templates to inherit from third party app templates with the same name.

Impossible without the help and insight of Pablo Martín (thanks!)