A powerful template handling logic with advanced features