empty ALT and TITLE tag

Author Message

laurent le cadet

Friday 04 August 2006 2:59:21 am

Hi,

The alt and title tags texts come from {$image.text|wash(xhtml)} (datatatype/view/ezimage.tpl).

I think it should be filled by default with the image title but in my case they are empty :(

Any hint ?

Thanks.

Laurent

Greg Sanderson

Tuesday 02 December 2008 8:59:13 am

Hi

I have a way to add alt and title attributes that seems to work.

You will need the str_replace extension function from http://ez.no/developer/contribs/template_plugins/string_replace_operator

Once this is active I then altered ezimage.tpl in (my design folder)/templates/content/datatype/view/ezimage.tpl, adding:

...

{def $image_name_without_hyphens=ezstr_replace('-',' ',$image.basename)}

<img src={$image.url|ezroot} width="{$image.width}" height="{$image.height}" {section show=$hspace}hspace="{$hspace}"{/section} style="border: {$border_size}px;" alt="{$image_name_without_hyphens|wash(xhtml)}" title="{$image_name_without_hyphens|wash(xhtml)}" />

...

This simply uses the name that you give the image when you upload it as the alt and title attributes, having stripped the hyphens that get added to basename out.

This also works for embedded images through the OE editor, but use $image_variation.basename instead for those.

André R.

Tuesday 02 December 2008 9:30:48 am

No need for str_replace, the object name is mostly what you specified in the upload dialog or the image name without the file extension anyway:
content/datatype/view/ezimage.tpl

{*
Input:
 image_class - Which image alias to show, default is large
 css_class     - Optional css class to wrap around the <img> tag, the
                 class will be placed in a <div> tag.
 alignment     - How to align the image, use 'left', 'right' or false().
 link_to_image - boolean, if true the url_alias will be fetched and
                 used as link.
 href          - Optional string, if set it will create a <a> tag
                 around the image with href as the link.
 border_size   - Size of border around image, default is 0
*}
{default image_class=large
         css_class=false()
         alignment=false()
         link_to_image=false()
         href=false()
         target=false()
         hspace=false()
         border_size=0}
{let image_content=$attribute.content}
{section show=$image_content.is_valid}

    {let image=$image_content[$image_class]}

    {if and( not( $href ), $image_class|ne( 'original' ) )}{set $link_to_image = true()}{/if}
    {section show=$link_to_image}
        {set href=$image_content['imagelarge'].url|ezroot}
    {/section}
    {switch match=$alignment}
    {case match='left'}
        <div class="imageleft">
    {/case}
    {case match='right'}
        <div class="imageright">
    {/case}
    {case/}
    {/switch}

    {section show=$css_class}
        <div class="{$css_class|wash}">
    {/section}

    {section show=and( is_set( $image ), $image )}
        {if and( is_set( $image.text ), $image.text|ne("") )}
            {def $img_alt_text = $image.text}
        {else}
            {def $img_alt_text = $attribute.object.name}
        {/if}
        {section show=$href}<a href={$href}{if $link_to_image} rel="lightbox[gallery]"{/if}{section show=and( is_set( $link_class ), $link_class )} class="{$link_class}"{/section}{section show=and( is_set( $link_id ), $link_id )} id="{$link_id}"{/section}{section show=$target} target="{$target}"{/section}>{/section}
        <img src={$image.url|ezroot} width="{$image.width}" height="{$image.height}" {section show=$hspace}hspace="{$hspace}"{/section} style="border: {$border_size}px;" alt="{$img_alt_text|wash(xhtml)}" title="{$img_alt_text|wash(xhtml)}" />
        {section show=$href}</a>{/section}
    {/section}

    {section show=$css_class}
        </div>
    {/section}

    {switch match=$alignment}
    {case match='left'}
        </div>
    {/case}
    {case match='right'}
        </div>
    {/case}
    {case/}
    {/switch}
    {/let}
{/section}
{/let}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Greg Sanderson

Thursday 04 December 2008 5:45:55 am

Yes, that's a better way

Where would $image.text usually come from? There doesn't seem to be any inputs for this when uploading an image..

Also, I was thinking that it would be even better if there were extra fields for both any caption, the alt text and the title text, instead of taking these all from the name of the image. I could add custom attributes that would apply to all embedded content for image uploads within the OE editor, but how would I do this for images through the template class structure? Only in my image class I have an XML Block called 'Caption' along with another field called 'Tags', yet I don't get a chance to input these when uploading an image.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 21:47:29
Script start
Timing: Jan 30 2025 21:47:29
Module start 'layout'
Timing: Jan 30 2025 21:47:29
Module start 'content'
Timing: Jan 30 2025 21:47:29
Module end 'content'
Timing: Jan 30 2025 21:47:29
Script end

Main resources:

Total runtime0.0265 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 588.1250151.2109
Module start 'layout' 0.00620.0044 739.3359220.6875
Module start 'content' 0.01060.0143 960.02341,001.8984
Module end 'content' 0.02490.0015 1,961.921937.9922
Script end 0.0264  1,999.9141 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00269.8842140.0002
Check MTime0.00103.6861140.0001
Mysql Total
Database connection0.00082.975710.0008
Mysqli_queries0.003513.063430.0012
Looping result0.00000.072010.0000
Template Total0.00114.110.0011
Template load0.00093.357510.0009
Template processing0.00020.759010.0002
Override
Cache load0.00062.368010.0006
General
dbfile0.00124.479380.0001
String conversion0.00000.037840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs