10690 Posts in 2797 Topics by 1519 members
Jump to:If this is your first visit, you will need to register before you can post. However, you can browse all messages below.
| Page: 1 | go to end | Reply | |
| Author | Topic: ParentID if lowerlevel pages, ID if not? Help! | 1027 views |

25 April 2008 at 11:26am
trying to make a different header image for specific pages based on their parent id..
the problem is that When you're on the ParentID page, it outputs '0' for a value.
How would I make it write it's own ID (when on the top level page) and write it's ParentID when you're on a child page?
id="header" class="ban$ParentID"
Thanks in advance!

25 April 2008 at 1:32pm
That is going to get broken pretty quick if you have to keep making classes for each page.
Have you thought about using a enum select for pages to select from a defined list of classes.. you could even use a dataobject list to setup new classes to make sure it is kept current.

25 April 2008 at 10:13pm
dancrew: I recommend that you make a little function on your Page class, HeaderClass:
it could be this:
function HeaderClass() {
if($this->ParentID) return "banner-" . $this->ParentID;
else return "banner-" . $this->ID;
}
But Blackdog's suggestion is better. For that, you could make an enum field called HeaderClass instead of the HeaderClass() function. :-)

26 April 2008 at 7:14am
Sam and Blackdog, I really appreciate the help.
Sam, I am new to this MVC deal, and I'm curious where you might implement the script you provided below. Would it be in mysite/code/page.php? How would I call it on my theme/page.ss?
$HeaderClass?
Sorry, new to this part of SS still. Thanks for any help you can provide. =]

26 April 2008 at 11:45am
Yes on both counts. HeaderClass() should either be inside class Page or class Page_Controller.
If it's inside class Page, then you will be able to access it inside a block such as <% control Menu(1) %> - getting the HeaderClass for each of the menu items. However, I'm sure not that you would ever want to do this.
If you put it inside class Page_Controller, then you will only be able to access it at the top level. For methods that don't make any sense to be used inside a <% control %> block, we usually put them on the controller.

6 May 2008 at 3:57am
Sorry, hopefully this is the last question... I just don't quite get how to implement the control from Page_Controller. Would it be like this?
<div id="header" class="<% control HeaderClass() %><% end_control %>">
my page controller class:
class Page_Controller extends ContentController {
function init() {
parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
function HeaderClass() {
if($this->ParentID) return "banner-" . $this->ParentID;
else return "banner-" . $this->ID;
}
}
(btw, this doesn't output anything in the class="" section for some reason.. any ideas?)
Last edited: 6 May 2008 at 3:58am

6 May 2008 at 9:06am
You're heading in the right direction.
Take the parenthesis off the <% control HeaderClass() %> inside the template, that isn't required and may be breaking. Also, you should be just returning $HeaderClass, as it's a single piece of text. The <% control HeaderClass %> block is used for a set of data returned, as opposed to a single string.
e.g.
<div id="header" class="$HeaderClass">
Last edited: 6 May 2008 at 9:08am
| 1027 views | |||
| go to top | Reply |