Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

render dataobjects with Page?


Go to End


3 Posts   3178 Views

Avatar
Bambii7

Community Member, 254 Posts

10 August 2010 at 1:41pm

hey all,
I'm still coming to terms with the contoller class. Don't understand yet how to customise URL variables. But have managed to work with default Action and ID which is about all I need (for now).

I have a page type "rental cars" which has many "car objects" attached. Rather than using child pages. To view a car object I've added this function to the rental cars page.

function Show() {
$URLParams = Director::urlParams();
$CarPage = DataObject::get_by_id('RentalCarObject', $URLParams['OtherID']);
return $this->customise(array("Car" => $CarPage))->renderWith("CarPage");
}

That's working for me when I enter mysite.com/rentalcarpage/show/1

The question is how to get this rendering as a Layout, so it's wrapped by the default Page?

I was about to copy paste all my styles and wrapper divs into "CarPage.ss", but this doesn't seem very intelligent. I've been meaning to suss this out for a while to handle large a number of DataOjects outside of the page tree.

Again help is much appreciated :)
Lex

Avatar
Willr

Forum Moderator, 5523 Posts

10 August 2010 at 2:10pm

I think if you pass an array of values (one being page) to the render with it should include the Page.ss and the CarPage.ss from layout

renderWith(array("CarPage", "Page")); 

Avatar
Bambii7

Community Member, 254 Posts

10 August 2010 at 2:32pm

HOT DANG! you're right.
Thank heaps for your help willr.
I checked it out on the API and you can pass a String or an Array http://api.silverstripe.org/2.4/sapphire/view/ViewableData.html#methodrenderWith

I've looked at it before but didn't make sense to me until you pointed it out.

Again many thanks.