View previous topic :: View next topic |
Author |
Message |
Roc Smarty Rookie
Joined: 17 Apr 2003 Posts: 15
|
Posted: Mon Apr 21, 2003 11:22 pm Post subject: html_image should generate alt attribute |
|
|
As I understood the recent HTML recommendations from the W3 consortium, every <img> tag should always contain an "alt" attribute, even if it's empty. The W3 validator throws an error when the alt attribute is missing (HTML 4+ or XHTML). |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 3:06 am Post subject: |
|
|
Good idea.
For now, replace the line that starts with "return ..." at the end of the function.html_image.php file with:
Code: | $alt = (empty($params('alt'))) ? $params('file') : $params('alt');
return $prefix . '<img src="'.$file.'" alt="'.$alt.'" border="'.$border.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix; |
This will have the alt text default to the filename if the optional alt parameter was not specified. |
|
Back to top |
|
Roc Smarty Rookie
Joined: 17 Apr 2003 Posts: 15
|
Posted: Sun May 04, 2003 11:17 am Post subject: |
|
|
I think, an empty attribute (alt="") will be better as default. Try to browse a web site with lynx, and you'll see the reason: if the attribute is missing, lynx will display the filename instead, which make pages containing a lot of layout gifs quite unusable. I only want to specify alt in that cases, where it makes sense to have a text description for the image - either it contains a link or provides an information valuable to the user. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun May 04, 2003 11:39 am Post subject: |
|
|
fixed in cvs.
alt defaults to "" now and is always returned by html_image.
it's some days ago i did this. i didn't commit before, since i waited for an enlightenment on
http://phpinsider.com/smarty-forum/viewtopic.php?p=999
i wanted to update these two issues in one stroke. but since i don't have a 100% nice solution for topic 999, i committed the fix for the alt="" tag now.
have fun
messju |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 12:03 pm Post subject: |
|
|
Quote: | I think, an empty attribute (alt="") will be better as default. |
I agree if the link attribute is being used. Otherwise, it is pointless to include an alt="". The reason it is required is to allow accessability to users not loading images. If the link is there, there is no issue--but with no link, alt="" and no image loading--well, it provides nothing except for document validation. I could have probably chose something better than the filename--but SOMETHING should be put there!!
See: http://htmlhelp.com/feature/art3.htm |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun May 04, 2003 12:24 pm Post subject: |
|
|
i agree with you, boots, that something should be put there. but something reasonable can only be put there by the template-maker and not by {html_image}. so the default "" is okay to me. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 12:49 pm Post subject: |
|
|
Then isn't it better to not have a default of ""? The document not-validating is the last chance for the designer to catch the error. If the designer really doesn't want an alt, as in the case of a link, then perhaps they can expressily indicate an alt="".
Anyhow, I'm using my own library for this, so I won't complain |
|
Back to top |
|
Roc Smarty Rookie
Joined: 17 Apr 2003 Posts: 15
|
Posted: Sun May 04, 2003 4:15 pm Post subject: |
|
|
Using the file name as alt value doesn't make sense in many cases since the file name is often auto generated (e.g. MD5 hash), especially in typical situations when you need html_image like showing data from a database (e.g. product pictures in a shop). Then it's better to have nothing in the browser than "95950955kj54kr9840.jpg", I think. |
|
Back to top |
|
|