17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 11196 Views |
-
Pseudocode for changing a theme/look of a website for each top-level-section of a website

29 February 2008 at 4:11pm Last edited: 29 February 2008 4:21pm
I was emailed on how to do to this. Here's untested pseudocode by Michael on a good approach. The code won't work exactly out of the box, but it gives you a start point. Post the working code back, please
1. Create a new variable that returns the section in your PHP.
2. Use the $section variable to set a class over the entire page
3. Use differently-named classes in your CSS file to change images, colours, etc.---------------
PHP:protected function Section($currentPage) {
if($currentPage->ParentID == 0) {
return $currentPage->URLSegment;
} else {
return $this->Section(DataObject::get_one("Page", "`SiteTree`.ID = $currentPage->ParentID AND ShowInMenus = 1"));
}
}--------------------------------
2. Add variable to template<html ... >
<body class="section$Section">
<h1>$Title</h1>
<div class="typography">
$Content
</div>
</html>--------------------------------
3. In your CSS, do.sectionHome h1 { background-image: url( homepage.jpg) }
.sectionHome .typography { color: blue };.sectionAboutus h1 { background-image: url( aboutus.jpg) }
.sectionAboutus.typography { color: green };.sectionServices h1 { background-image: url( services.jpg) }
.sectionServices .typography { color: pink }; -
Re: Pseudocode for changing a theme/look of a website for each top-level-section of a website

2 March 2008 at 4:28pm Last edited: 2 March 2008 4:32pm
Hi,
Here is the part to find the page if it at the top level.
-----------------------------------------------------------------
In newpage.php<?php
/**
* Defines the NewPage page type
*/class NewPage extends Page {
static $db = array(
);
static $has_one = array(
);}
class NewPage_Controller extends Page_Controller {
protected function WhatPage()
{
$page_id1 = $this->ParentID;
if($page_id1 == 0) {
$filename = $this->URLSegment;
return $filename;
}
}
}
?>In the .ss template
<head>
<% base_tag %>
<link rel="stylesheet" type="text/css" href="tutorial/css/layout.css" />
<link rel="stylesheet" type="text/css" href="tutorial/css/typography.css" />
<link rel="stylesheet" type="text/css" href="tutorial/css/form.css" />
</head>
<body>
<div id="Main" align="center">
<div id="header$WhatPage">
<div id="Content" class="typography" align="left">
$Content
$Form
</div>
</div>
</div>
</body>In the CSS file
#headeraccessories {
background-image: url(/jpgimages/<image>.jpg);
background-position:center;
background-repeat:no-repeat;
height: 1079px;
top:0px;
}-------------------------------------------------------------
This works like a charm for the pages in the top level.Still working on the code for children pages, so far I have:
else {
$sitetreeid=$this->ParentID;
$filename= DataObject::get_one("SiteTree","ParentID=$sitetreeid");
$filename1=$filename->URLSegment;
return $filename1;
}But this returns the base pagename of NewPage, not the Top Level page name. I'm still working on it, but if anyone has any ideas, that would be great.
-
Re: Pseudocode for changing a theme/look of a website for each top-level-section of a website

7 April 2008 at 8:55am
Here's the final code
protected function WhatPage($currentPage)
{
if (!$currentPage) {
$page_id1 = $this->ParentID;
}
else
{
$page_id1 = $currentPage->ParentID;
}if($page_id1 == 0) {
$filename = $this->URLSegment;
return $filename;
}
else {
$sitetreeid=$this->ParentID;
$test1= DataObject::get_by_id("Page","$sitetreeid");
$pageid2 = $test1->ParentID;
if ($pageid2 ==0) {
$filename = $test1->URLSegment;
return $filename;
}
else {
$test3= $test1->URLSegment;
return $this->WhatPage($test3);
}
}
}
| 11196 Views | ||
|
Page:
1
|
Go to Top |


