I don't think that the if statement can go inside the layout, as inside of it there are calls to member functions, however I can move JHtml calls to layout file, if that's satisfying?