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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Access dataobjects from page in virtual page


Reply


4 Posts   2105 Views

Avatar
Martiman

Community Member, 7 Posts

26 August 2009 at 8:23am

Hi,

I defined a new dataobjects in my page controller (Image), which i display in pages with $BannerImage. Every normal page has its own image.

However, this does't work on virtual pages; there doesn't seem to be a image there. Of course i want to use the image defined for the normal page used by the virtual page.

How can I access the dataobjects from the original page in a virtual page?

Avatar
Martiman

Community Member, 7 Posts

27 August 2009 at 12:28am

Nobody any idea? This can't be so hard..

Avatar
LinseyM

Community Member, 99 Posts

7 October 2009 at 10:42pm

I think it might be because the data object is defined in the "Page" pagetype, whereas this is a "virtual page" type.

I'm having a similar problem with a user defined form.

Avatar
zenmonkey

Community Member, 528 Posts

30 December 2009 at 8:40am

I've come up with a bit of hack to get some functionality Custom Functionality. Unfortunately the Virtual Page uses the Page Template Class by default.

If you add the Following to your VirtualPage.php you can get some better rendering control:

function index() { // index runs if no other function is being called - it is like a second init()
    $realPage = $this->ContentSource()->ClassName;
    if($realPage != "Page") {
    return $this->renderWith("Virtual".$realPage);
    }
    else {
    return Array();
    }
    }

You need to then create a root template with the name Virtual(Original Page Class). Unfortunately this all but eliminates some of the modularity the template system provides. In this template then wrap anything that calls Custom Data with

<% control ContentSource %> <% end_control %>


This will let you access all the custom Data from the Original Pagetype.

I still haven't figured out a way to enable Custom Forms and Functions beyond copying to the VirtualPage type and modifying their calls to use the ContentSource Method