Sign In  |  Cart  |  Join Now

Page-specific Body Tag

May 11, 2009
Hi,

Is there a way to allocate a specific ID or Class tag to the Body tag of a page to allow specific styling of that page?

For example, say I wanted to give the News pages some specific styling (the main News page and all those child pages under it), is there a way to change the body tag from
<body>

to
<body id="news">

or something similar on those pages only?

Obviously a bit of PHP is needed, possibly using similar functionality to the autonav block to fetch the page's location within the site and place this in the correct place.

I realise I could create a separate template for each section of the site, but I thought this would be a more elegant solution.

Thanks in advance for any help.
Tony.

yes

May 11, 2009 at 5:51 PM
<body id="<?php echo $c->getCollectionHandle()?>">
 

Child pages are given their own ID

May 12, 2009 at 4:10 AM
Thanks for your help Remo.

That works great for the main pages in the site, but I really wanted child pages to inherit their parents value.

For instance, if I had a page called 'Services' and under that 'Services1' and 'Services2', using getCollectionHandle would give those last two pages IDs of Services1 and Services2, not Services as I would prefer.

I'm looking forward to when the end user is updating the site himself. As he adds pages under main sections those pages need to share their parents styling.

Thanks again,
Tony.
 

get top level handle

May 12, 2009 at 5:34 AM
sorry, didn't read your question too quickly.

not sure if this is the proper way, there's probably a better function somewhere in the api but this should also work, even if it's ugly:

$urls = split('/',$c->getCollectionPath());
echo $urls[1];
 

woah

May 12, 2009 at 12:38 PM
you are way over solving this problem

Use page types for the different areas, make them all include the same template file and switch on the page type for your customization

concrete5 was designed with that very much in mind so that will always work, unlike some funky hack around the URL.

if you have advanced permissions mode on you can limit which user groups can add which page types from which parts of the site as well.
 

I agree with Franz.

May 12, 2009 at 12:57 PM
You could just use the Page Type.

When you create the new theme.... in addition to

============
default.php
view.php
============

You can create

============
news.php
============

And then... just indicate the ID there....

When you stick the cID, I can see the maintenance nightmare...
 
 

Hot Spots...

ForumsPartners | Contact | Blog

Search site