This probably has something to do with other code in the template, because, assuming that there is an endif;
line that you’re not including, there is nothing wrong with the small section of code that you gave. Can you provide a more significant portion of the code involved.