Fix #15053: Better template loading

Code is from overextends by:
- Stephen McDonald
- Mitar
- Stefan Wehrmeyer