Recursive template engine