We don't like any logic in the template. Please move it to where the variables for the template are set and pass either the link below or an empty string to the template.