First off, here are my references:
http://forum.umbraco.org/yaf_postst2885_RenderMacroContent--Help.aspx
http://en.wikibooks.org/wiki/Umbraco/Reference/umbraco.library/RenderMacroContent
Between the two of these solutions, I eventually got this to
work. I was trying to get a general purpose way of using ImageGen,
which in the end doesn't make all that much sense as the gains of
doing it this way are minor. But anyway, the theory holds for how
to pass parameters to your rendered macro.
I have a macro called ShowImageGenImage, which takes an image
Id, the height and width of the image and displays it. It doesn't
care where in the site the current node is - it's a general purpose
macro for spitting out an image of a certain size, given the image
ID and the required height and width. This can be used anywhere on
the site and for any image.
On each product page in my site, I want to display the image
associated with the current node, with a height and width of 200px
(the site is laid out one node per product, each product node
having an attribute called "image").
Here is my ShowProductImage.xslt. It uses CDATA to encode the
macro properly, while allowing the variable values to be inserted.
I had tried to encode these directly, but for example my $imageId
variable was coming through as the string "$imageId" instead of the
actual value, in this case 1063. The height and width are passed in
as parameters to the macro, but the $imageId comes from the current
node.
Hope that helps!
David
P.S. Yes I will get some styles sorted out for inserting code
into the blog, and yes, the RSS feed will appear here
eventually...
<?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:param name="currentPage"/>
<xsl:param name="width" select="/macro/width"/>
<xsl:param name="height" select="/macro/height"/>
<!-- For use on the product page. Passes the image ID (alias is "image") of the current node to the -->
<!-- ShowImageGenImage macro to display it. Height and width come from the template. -->
<xsl:template match="/">
<!-- create the escaped macro string with variable values set to be passed to RenderMacroContent, below -->
<xsl:variable name="macro">
<![CDATA[<?UMBRACO_MACRO macroAlias="ShowImageGenImage" imageId="]]>
<xsl:value-of select="$currentPage/data[@alias='image']"/>
<![CDATA[" height="]]><xsl:value-of select="$height"/>
<![CDATA[" width="]]><xsl:value-of select="$width"/>
<![CDATA["></?UMBRACO_MACRO>]]>
</xsl:variable>
<xsl:value-of select="umbraco.library:RenderMacroContent($macro, $currentPage/@id)" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>