Jump to:

22977 Posts in 11742 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Trying to understand writing controls

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: 990 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    Trying to understand writing controls Link to this post

    In the tutorial about the staff section that uses a has_many array to store an image for the page type. I see that in the ss page using $Photo returns an entire img tage with source etc. I want to just get the filename of the image. In my controller I added a function like this:

    public function ImageFilename() {
    return $this->Photo->Filename;
    }

    This does not work but I am wondering why it doesn't work so I can better understand how SS works.

  • rgo
    Avatar
    Community Member
    13 Posts

    Re: Trying to understand writing controls Link to this post

    If you code $ImageFilename inside de ss file it should works!

    $this->Photo->Filename is not empty?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Trying to understand writing controls Link to this post

    Hi

    I believe this is because retreiving an asset which is attached to a class via a has_one etc actually uses a method of the same name.
    So calling $this->Photo()->Filename should work fine.

    Anyway you can do this without any complicated stuff by just calling $Photo.URL in your template which will just return the relative URL of the image.

    Hope that helps

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