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.

Archive /

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

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

Images, Templates and alt attributes


Reply


2 Posts   1704 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 [url]http://api.silverstripe.com/default/Image.html#URL[/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"/>