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.

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   2323 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"/>