Forum

Thread tagged as: Question

Get url segment added to perch_custom_content

I have brand guidelines site with sections for each different brand e.g:

/brand-name-one

/brand-name-two

/brand-name-three

then

/brand-name-one/logo/

/brand-name-one/logo/variations

/brand-name-one/colours/

/brand-name-one/colours/usage

etc etc

Each brand index.php has a region for 'brand name', as the site shares templates the identifier is 'brand name' displayed on the page loaded like so:

// Used to identify which section of the site you're in
// Taken from the Brand overview page for each brand
perch_content_custom('Brand name', array(
    'page'=> '/BRAND-NAME/index.php',
    'filter' => 'brand-name',
    'template' => 'brand-name.html'
));

On 'page' how do I get it to add the brand-name from first segment of the url:

    'page'=> '/brand-name/index.php',

or is there a better way to do this?

Mark Watts

Mark Watts 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is it the current page? If so, you don't need to specify the page attribute.

Not current page, taken from the top level page of the brand section. So it's been pulled from different levels within that section e.g. /brand-name/logo/variations

It would be good to have this also added to the body as a class.

there are 6 brands so wanted to keep things simple and just customise the bits required. e.g. brand name, body class etc

Drew McLellan

Drew McLellan 2638 points
Perch Support

The simplest way to pop it out of the URL is:

$segments = explode('/', PerchSystem::get_page());
$brand = PerchUtil::html($segments[1]);

Then $brand contains your brand name. You could use it like this:

'page'=> "/$brand/index.php",

That's fantastic, thanks! Works perfectly and I can use if for the body class for css hooks too :o)

Here's how the page template looks:

include($_SERVER['DOCUMENT_ROOT'] . "/admin/runtime.php");

// Get URL segment 1
$segments = explode('/', PerchSystem::get_page());
$brand = PerchUtil::html($segments[1]);

// Loads the global header template /admin/templates/layouts
// Dynamically Loads page title from the Page Details in the CMS
// Applies 'page' class to body tag in header from current URL
perch_layout('global.header', array(
        'title' => perch_page_title(true),
        'page' => $brand
    ));

// Used to identify which section/brand of the site you're in
// Taken from the Section/Brand overview page for each section/brand
perch_content_custom('Brand name', array(
// Depending on what URL is current (which section/brand) taken from URL Segment 1
    'page'=> "/$brand/index.php",
    'filter' => 'brand-name',
    'template' => 'brand-name.html'
));

echo ' | Brand guidelines';

// Information entered in the CMS
perch_content('Overview');  
perch_content('Details');   

// Loads member sidebar from global template /admin/templates/layouts
perch_layout('global.sidebar', array(
    'member'    => true,
));

// Loads the global footer template /admin/templates/layouts
perch_layout('global.footer');