Extract common code for adding sections to pages.