Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17480 Posts in 4474 Topics by 1973 members

Archive

SilverStripe Forums » Archive » Alt text on images

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

Page: 1
Go to End
Author Topic: Alt text on images 445 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
    103 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

    445 Views
Page: 1
Go to Top

Currently Online: entercow

Welcome to our latest member: marcusl

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

Comments on this website? Please give feedback.