Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sophie Mitchell 23 posts 43 karma points
    Mar 27, 2012 @ 12:11
    Sophie Mitchell
    0

    Add height, width and alt tag to image rendered by media picker

    Hello,

    I've used this code:

    <umbraco:Item runat="server" field="image" xslt="concat('&lt;img src=&quot;',umbraco.library:GetMedia({0}, true())/umbracoFile, '&quot; /&gt;')" xsltDisableEscaping="true"/>

    in my template to display a defined header image on each page of my site (using the media picker) and it works perfectly.

    Is there a way to add a specific width and height to this code? Also a way for it to generate the alt tag for the image?

     

    Thanks,


    Sophie

  • Grant Thomas 291 posts 324 karma points
    Mar 27, 2012 @ 12:48
    Grant Thomas
    0

    Just alter your XSLT part of it to include the sizes necessary:

    <umbraco:Item runat="server" field="image" xslt="concat('&lt;img style=&quot;width:XX; height: XX;&quot; src=&quot;',umbraco.library:GetMedia({0}, true())/umbracoFile, '&quot; /&gt;')" xsltDisableEscaping="true"/>

  • Sophie Mitchell 23 posts 43 karma points
    Mar 27, 2012 @ 16:25
    Sophie Mitchell
    0

    Thank you - I've done that and added the alt tag as well. Is there a way to generate the alt tag from the file name? Or, does it need to be hard coded?

    Thanks

  • Grant Thomas 291 posts 324 karma points
    Mar 27, 2012 @ 16:49
    Grant Thomas
    0

    To be honest, if you're going to extend this any further I would wrap it in a macro and do something a bit like this (you may need to tweak it):

    <xsl:variable name="media" select="umbraco.library:GetMedia({0}, true())"/>
    <xsl:element name="img">
      <xsl:attribute name="width">100</xsl:attribute>
      <xsl:attribute name="height">100</xsl:attribute>
      <xsl:attribure name="alt">
        <xsl:value-of select="$media/nodeName" />
      </xsl:attribute>
      <xsl:attribute name="src">
        <xsl:value-of select="$media/umbracoFile"/>
      </xsl:attribute>
    </xsl:element> 
Please Sign in or register to post replies

Write your reply to:

Draft