Jump to:

23358 Posts in 17874 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Getting image from another template

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: 589 Views
  • sca123
    Avatar
    Community Member
    61 Posts

    Getting image from another template Link to this post

    Hi

    I have an image that is used on the homepage (HomePage.php) as per the following code:

    public static $has_one = array(
       'Image1' => 'Image'
    );

    I then wish to use the same image throughout the site (Page.php)

    I have tried using;

    public function Image1(){
    $obj = SiteTree::get_one('HomePage');
    return $obj->Image1;
    }

    But it just gives me an error. I am also trying to do the same with Content1 which is an HTMLText field, but that throws the same error

    Any ideas??

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Getting image from another template Link to this post

    $obj = SiteTree::get_one('HomePage');

    SiteTree::get_one is not a function you're looking for DataObject::get_one. If you have display errors on in your php.ini file and devmode on you should have got a pretty clear error message - if you just got a blank page you might want to turn both options on.

    You can also do this in your template if you want.

    <% control Page(home) %>
    $Image1
    <% end_control %>

    589 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.