If the layout is not set, couldn't this just be:

`{% if page.layout %}`