move layout.ctp logic from pages controller to app controller