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!)
Refs #15053 -- make cache loader compatible with self-referenced inheritance

Thank you Unai Zalakain for updating the documentation.