Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Alt text on images

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

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

Page: 1
Go to End
Author Topic: 1734 Views
  • superautomatic
    Avatar
    Community Member
    53 Posts

    Alt text on images Link to this post

    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?

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Alt text on images Link to this post

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

  • superautomatic
    Avatar
    Community Member
    53 Posts

    Re: Alt text on images Link to this post

    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

    1734 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.