Optimize variable condition in layout