Say you're building a site with several products. Each product has it's own page and several subpages. All of these pages look and function the same, so you plan to create a single "Product" page type for all product pages/subpages. Each page has a sidebar with contact information. The tricky part is each product has it's own contact information and you don't want to make your editor retype contact information on each individual product page and it's subpages.

At first, this seems like perfect situation for Global Areas. They act just like a regular area (as far as your everyday C5 editor is concerned). The main difference is that these areas stay in-sync across every page that has that Global Area.

So we could do this:

<?php
    $a = new GlobalArea('Product Sidebar');
    $a->display($c);
?>

But this only gets us part way. Every product page now has the same sidebar that is editable on any page. However, the tricky part is we want each individual product to have a sidebar with it's own contact information. To accomplish this, each GlobalArea() call needs a unique handle shared by each main product page and it's subpages.

The solution? One good way to guarantee uniqueness is to add the main product page's cID to the GlobalArea() call.

<?php
    		
	// use navigation helper to get trail ancestor pages
	$nh = Loader::helper('navigation');
	$pageTrail = $nh->getTrailToCollection($c);
	
	// find main product page by traversing up tree (defaults to current page, replaced if a parent has "product" page type)
	$productMainPage = $c;
	foreach ($pageTrail as $page) {
		// if parent page is of our page type (we know it's "Product", but this avoids typos and possible name changes)
		if ($page->getCollectionTypeHandle() == $c->getCollectionTypeHandle()) {
			$productMainPage = $page;
		}
	}	
	
	// define a unique global area with the main product page's cID
	$a = new GlobalArea('Product ' . $productMainPage->cID . ' Sidebar');
	$a->display($c);
	
?>

There we have it, productwide/sectionwide sidebar areas.