However if the maxWidth property is omitted I need to get the width of the image (upload) width [@alias='umbracoWidth' and use that.
Additionally some sort of check so that the maxWidth value is only used if the width of the image is greater than the maxwidth integer. This is so that the design is not broken within a floated div.
This is isn't working. Would appreciate some help.
There's a couple of problems with your script I believe.
The fist one being that you can't reassign the maxWidth variable in XSLT so you need to change part of your script to allocate a new variable for maxWidth (same with altText)
<xsl:variable name="maxWidth_2"> <xsl:choose> <xsl:when test="$maxWidth != ''"> <xsl:value-of select="$maxWidth"/> </xsl:when> <xsl:otherwise> <!-- You need to fix this line too --> </xsl:otherwise> </xsl:choose> </xsl:variable>
Display an image with parameters
Hello,
I am sure that this has been covered before but I have modded a XSLT from the CWS to display images.
However my mod isn't working as expected.
I want to pass the variables propertyAlias, altText and maxWidth to a XSLT script.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:variable name="propertyAlias" select="/macro/propertyAlias" />
<xsl:variable name="altText" select="/macro/altText" />
<xsl:variable name="maxWidth" select="/macro/maxWidth" />
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="altTextValue">
<xsl:choose>
<xsl:when test="$altText != ''">
<xsl:value-of select="$altText"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$currentPage/@nodeName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="maxWidth">
<xsl:choose>
<xsl:when test="$maxWidth != ''">
<xsl:value-of select="$maxWidth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$maxWidth [@alias='umbracoWidth']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$currentPage/data [@alias = $propertyAlias] != ''">
<img src="{$currentPage/data [@alias = $propertyAlias]}" alt="{$altTextValue}" width="{$maxWidth}" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
However if the maxWidth property is omitted I need to get the width of the image (upload) width [@alias='umbracoWidth' and use that.
Additionally some sort of check so that the maxWidth value is only used if the width of the image is greater than the maxwidth integer. This is so that the design is not broken within a floated div.
This is isn't working. Would appreciate some help.
Hi,
There's a couple of problems with your script I believe.
The fist one being that you can't reassign the maxWidth variable in XSLT so you need to change part of your script to allocate a new variable for maxWidth (same with altText)
<xsl:variable name="maxWidth_2">
<xsl:choose>
<xsl:when test="$maxWidth != ''">
<xsl:value-of select="$maxWidth"/>
</xsl:when>
<xsl:otherwise>
<!-- You need to fix this line too -->
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$currentPage/data [@alias = $propertyAlias] != ''">
<img src="{$currentPage/data [@alias = $propertyAlias]}" alt="{$altTextValue}" width="{$maxWidth_2}" />
</xsl:if>
This should work for when you pass a macro value.
Let us know if this works, then we can move on to getting the width from the actual image.
Also it's better to actually resize images using the excellent http://our.umbraco.org/projects/website-utilities/imagegen but maybe better to deal with one thing at a time.
Rich
Actually that probably wont display an image but the width should work.
What is "propertyAlias" that you are passing, a media picker value?
Also which version of Umbraco are you using.
Rich
Hi Rich Green.
Quick response.
Actually the maxWidth variable worked just great, but obvioulsy I don't want to use a system varable so I have changed it to "maxPropertyWidth"
The code is called in the template :
<umbraco:Macro Alias="DisplayArticleImage" propertyAlias="productPic1" maxPropertyWidth="540px" runat="server"></umbraco:Macro>
540px is the maximum width of the div so the image should not exceed that. Note that the variable altText is ommited so the @nodename is used
The propertyAlias is the name of the upload field in the current page.
Everything works except if you omit the maxPropertyWidth the image won't display. Presumably it thinks its width is 0
is working on a reply...