adding a body ID as css hook
Code: Select all
<?php
/*
just a sample how to inject body ID - i.e. to allow specific CSS based things (or JavaScript stuff too)....
if you define $content['body_id'] = FALSE body tag injection will be hopped
sample will set body tag injection based on "main structure"
if it is in home it will fall back to
*/
if(isset($LEVEL_ID[1])) { // lets say it is the main structure root
$content['body_id'] = $LEVEL_ID[1];
{
if(isset($LEVEL_ID[3])) { // lets say it is the third structure level
$content['body_id'] = $LEVEL_ID[3];
}
}
} else { // do nothing
$content['body_id'] = false;
}
?>
Now wondering how to get this going for certain branches ov the structure tree...
now I'm beginning to see it: defining a class (myclass_) in custom.settings.php will give me a custom class with level myclass_id if I choose this template for a certain structure item (and this one only) - aha! besides the id if wanted. Cool, really cool. I understand... will dig deeper... cool... thanks...
- swisscheese
- Posts: 138
- Joined: Mon 19. Feb 2007, 16:37
- Location: Solothurn, Schweiz
Did a bit of researches and finaly would propose a little change of code. For sure OG will kill me or implement this in a future release (I hope the latter... ).
EDIT: Don't do it, there is a solution without fiddling in the core code. see post below
So here's how to go:
in /include/inc_front/content.func.inc.php replace line 127-145 with:
in /index.php replace line 145-157 with this:
if you give some values in the conf.template_default.inc.php like this:
you get something like this for a level with id 11 whithin a level with id 3:
Now, you could set in your css attributes for body.myclass_3 and all sublevels of this are affected.
You can try it here: http://www.zeltnerweg9.ch/index.php
Have fun
swisscheese
EDIT: Don't do it, there is a solution without fiddling in the core code. see post below
So here's how to go:
in /include/inc_front/content.func.inc.php replace line 127-145 with:
Code: Select all
//define the current article category ID
$content["cat_id"] = $aktion[0];
//try to find current tree depth
$LEVEL_ID = array();
$LEVEL_KEY = array();
$LEVEL_STRUCT = array();
$level_ID_array = get_breadcrumb($content["cat_id"], $content['struct']);
$level_count = 0;
foreach($level_ID_array as $key => $value) {
$LEVEL_ID[$level_count] = $key;
$LEVEL_KEY[$key] = $level_count;
$LEVEL_STRUCT[$level_count] = $content['struct'][$key]['acat_name'];
if($PERMIT_ACCESS && $content['struct'][$key]['acat_regonly']) {
$PERMIT_ACCESS = false; // only users have been logged in get access
}
$level_count++;
}
$content['body_id'] = $LEVEL_ID;
Code: Select all
// inject body tag in case of class or id attribute
$body_inject = '<body';
if($content['body_id'] !== false) {
if(!empty($template_default['body']['class'])) {
$body_inject .= ' class="';
foreach($content['body_id'] as $val) $body_inject.=$template_default['body']['class'].$val.' ';
$body_inject .='"';
}
if(!empty($template_default['body']['id'])) {
$body_inject .= ' id="'.$template_default['body']['id'].array_pop($content['body_id']).'"'; #gm#
}
}
$content['page_start'] .= $body_inject.'>'.LF;
if you give some values in the conf.template_default.inc.php like this:
Code: Select all
$template_default['body']['id'] = 'myid_';
$template_default['body']['class'] = 'myclass';
Code: Select all
<body class="myclass_0 myclass_3 myclass_11 " id="myid_11">
You can try it here: http://www.zeltnerweg9.ch/index.php
Have fun
swisscheese
Last edited by swisscheese on Thu 15. Nov 2007, 08:59, edited 1 time in total.
- Oliver Georgi
- Site Admin
- Posts: 9889
- Joined: Fri 3. Oct 2003, 22:22
- Contact:
- swisscheese
- Posts: 138
- Joined: Mon 19. Feb 2007, 16:37
- Location: Solothurn, Schweiz
Thanks Oliver. I made a frontend_render script:
Altough: this will ad another div around the whole content. I don't have access to $content['page_start'] in frontend_render, do I? If I had, I could preg_replace the body tag...
have fun
swisscheese
Code: Select all
if(count($LEVEL_ID)) {
foreach($LEVEL_ID as $val) $bodyclass .= $template_default['body']['class'].$val.' ';
$content['all'] = '<div class="'.$bodyclass.'">'."\n".$content['all']."\n</div>\n";
}
have fun
swisscheese
- Oliver Georgi
- Site Admin
- Posts: 9889
- Joined: Fri 3. Oct 2003, 22:22
- Contact:
all you have to do - inject these vars
and maybe set
in your frontend render script.
Oliver
Code: Select all
$template_default['body']['id'] = '';
$template_default['body']['class'] = '';
Code: Select all
$content['body_id'] = '';
Oliver