inc/parsers/templates.php
This very complex parser handles transclusion, functions and templates, in fact everything with curly brackets.
It handles also the special template {{}} that includes the main page from a language subpage.
The parser uses also regex. This limits the use from templates as arguments within other templates. Using arguments with triple brackets is no problem, but double brackets are not always resolved. However, you can workaround this knowing that the parser works straightforward and replaces all instances of a template at once So you can add the template on the top and comment it out. See Transclusion.
While the other parsers replace the wikitext with predefined text, the template parser may include text that contains new transclusions to resolve. Therefore, at the end, as long as both {{ and }} are present in the string, the entire string is parsed again.
System Messages are cached during the http Request so the file are not opened twice.
Note: It is your responsability to prevent templates that creates infinite loops.