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

Alt text on images


Go to End


3 Posts   2402 Views

Avatar
superautomatic

Community Member, 53 Posts

22 October 2008 at 8:41pm

Edited: 22/10/2008 8:43pm

Hi,

I am using resized images in a couple of templates, and was wondering how to set the alt attribute on those.

I've extended the Page class with

static $has_one = array(
		'Photo' => 'Image',
	);

and I call the image in the template with:

<% if Photo %>
      $Photo.SetWidth(130)
<% end_if %>

And thats all fine. But say I would like to use the image title (set in Files & Images) as the alt text for the image - How do I do that?

Avatar
ajshort

Community Member, 244 Posts

22 October 2008 at 8:58pm

Hey superautomatic,

You should be able to do something like this:

<% if Photo %>
	<% control Photo.SetWidth(130) %>
		<img src="$URL" alt="$Title"/>
	<% end_control %>
<% end_if %>

Avatar
superautomatic

Community Member, 53 Posts

22 October 2008 at 9:18pm

Thanks a lot for a quick response!

Your suggestion seems to work fine, except that $Title doesn't seem to be the name of the variable holding the image title (the alt field in the generated html is still blank).

So, anyone knows the name of the image title variable? (or where to find it in the documantation...)

/Jens