Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Access dataobjects from page in virtual page

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

Page: 1
Go to End
Author Topic: 2072 Views
  • Martiman
    Avatar
    Community Member
    7 Posts

    Access dataobjects from page in virtual page Link to this post

    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?

  • Martiman
    Avatar
    Community Member
    7 Posts

    Re: Access dataobjects from page in virtual page Link to this post

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

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Access dataobjects from page in virtual page Link to this post

    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.

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Access dataobjects from page in virtual page Link to this post

    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

    2072 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.