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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Trying to understand writing controls


Go to End


3 Posts   1456 Views

Avatar
micahsheets

Community Member, 165 Posts

14 April 2009 at 8:48am

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

Community Member, 13 Posts

14 April 2009 at 9:10am

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

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

Avatar
Carbon Crayon

Community Member, 598 Posts

14 April 2009 at 10:27am

Edited: 14/04/2009 10:30am

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