added checks to prevent rendering of template content where template has not yet been shown