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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Images, Templates and alt attributes


Go to End


2 Posts   2080 Views

Avatar
greg.tidwell

Community Member, 6 Posts

16 January 2008 at 3:55am


Hello,
I need the alt attribute of my image to be the title of the page it is being viewed on. any ideas?

class StaffPage extends Page{
.....
static $has_one = array(
'Photo' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
return $fields;
}
}

Avatar
hitautodestruct

Community Member, 19 Posts

16 January 2008 at 4:26am

Check out the Image API http://api.silverstripe.com/default/Image.html#URL
There are a lot of different methods that you can use but I think this should be a good solution:

<img src="$Photo.getFullPath" alt="$Title"/>