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.


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

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

Alt text on images


3 Posts   1749 Views


22 October 2008 at 8:41pm (Last edited: 22 October 2008 8:43pm), Community Member, 53 Posts


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 %>
<% 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?


22 October 2008 at 8:58pm Community Member, 244 Posts

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 %>


22 October 2008 at 9:18pm Community Member, 53 Posts

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...)