Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello,
I've used this code:
<umbraco:Item runat="server" field="image" xslt="concat('<img src="',umbraco.library:GetMedia({0}, true())/umbracoFile, '" />')" 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
Just alter your XSLT part of it to include the sizes necessary:
<umbraco:Item runat="server" field="image" xslt="concat('<img style="width:XX; height: XX;" src="',umbraco.library:GetMedia({0}, true())/umbracoFile, '" />')" xsltDisableEscaping="true"/>
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
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>
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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('<img src="',umbraco.library:GetMedia({0}, true())/umbracoFile, '" />')" 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
Just alter your XSLT part of it to include the sizes necessary:
<umbraco:Item runat="server" field="image" xslt="concat('<img style="width:XX; height: XX;" src="',umbraco.library:GetMedia({0}, true())/umbracoFile, '" />')" xsltDisableEscaping="true"/>
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
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>
is working on a reply...