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

Trying to understand writing controls


Reply

3 Posts   1033 Views

Avatar
micahsheets

14 April 2009 at 8:48am Community Member, 164 Posts

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.

Avatar
rgo

14 April 2009 at 9:10am Community Member, 13 Posts

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

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

Avatar
Carbon Crayon

14 April 2009 at 10:27am (Last edited: 14 April 2009 10:30am), Community Member, 598 Posts

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