I have just upgraded to Umbraco 4 and took the opportunity to move some of my macros over to XSLT for ease of maintenance. However, I'm stuck when trying to create one of these things.
I based the XPath from a blurb I saw somewhere on the web but it was written for Umbraco 3 - either I completely misunderstood the XML structure or something has changed from Umbraco 3 to 4. Can someone please help me get the correct XPath to obtain the umbracoFile value?
Your code looks right and I pasted it directly to one of my macros using the macro parameter name and type and it appeared just fine.
Try adding ?umbDebug=true to the end of the page address to see what the macro is passing you. The only case it might not show up is if a Folder is selected vs and image, and so there would be no file. umbDebug should be able to show you the exact data passed.
Thanks Chris - I will give that a try. I take it you created a parameter with selectedMedia alias of the mediaCurrent type? On my site it simply returned a "Hello World" image. I'm guessing that's the default image when the real one cannot be found?
Could not write XML node (selectedMedia) Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at umbraco.macro.addMacroXmlNode(XmlDocument umbracoXML, XmlDocument macroXML, String macroPropertyAlias, String macroPropertyType, String macroPropertyValue) at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
It seems to have a problem generating the XML in the first place I'm guessing - I'm not sure what I have done differently from you, Chris.
Could not write XML node (selectedMedia) Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at umbraco.macro.addMacroXmlNode(XmlDocument umbracoXML, XmlDocument macroXML, String macroPropertyAlias, String macroPropertyType, String macroPropertyValue) at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
It seems to have a problem generating the XML in the first place I'm guessing - I'm not sure what I have done differently from you, Chris. Here's the output of Visualize XSLT tool:
<DIV style="PADDING-BOTTOM: 7px; PADDING-LEFT: 7px; PADDING-RIGHT: 7px; MARGIN-BOTTOM: 15px; MARGIN-RIGHT: 10px; PADDING-TOP: 7px"><A title="" href="" rel=lightbox><IMG style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none" class="reflect rheight25 ropacity35" src="/umbraco/imageGen.aspx?image=&width=230&height=115&constrain=true"></A></DIV>
It seems to have not inserted the appropriate image value for imageGen at all. Can you please clarify this is how I should use this macro?
Create a new node, and in the editor I insert this macro, and select the appropriate Media node/item as the selectedMedia value - that's all, right?
I glanced at the umbraco source code and it looks like there is being thrown while looping through the macro properties trying to generate the xml node. Which makes me think something happened while creating the macro, in the macros section not inserting it on the page.
In the Macros section try removing the parameter 'selectedMedia' from the macro and saving the macro, then add the parameter back in and save. Hopefully this will re-create the macro parameter correctly this time, which for whatever reason it didn't last time.
Also go back to your node and re-insert the macro just to be safe.
If that doesn't work try recreating the macro completely, but you can use the same XSLT file.
Hi Chris, I have recreated a new Macro, with a new name, but the same parameter name and the same XSLT. Unfortunately it's still not working. I'm really stumped about this - it seems simple enough.
On the Parameters tab in the Macro's dashboard, what does the "Show" tickbox do? If you have a spare moment can you possibly outline the steps you took in creating each item from XSLT, Macro, and new Content node? My new content node is just a simple Document type with two data fields, one with alias "heading" (text string) and another with alias "bodyText" (Richtext). The macro is inserted into the bodyText field.
Can you think of any potential source of problems in these steps? I think bodyText may be a reserved Umbraco field name, like umbracoFile or some such, isn't it? Can that be a problem?
As with the other problem I posted previously, one which used umbracoRedirectId, this feels like some weird caching issue. When I started up my VM again this morning it all worked just fine.
If anyone is interested in a macro to insert a thumbnail which opens up the image in a lightbox here it is:
Macro with a mediaCurrent parameter
Hi folks,
I have just upgraded to Umbraco 4 and took the opportunity to move some of my macros over to XSLT for ease of maintenance. However, I'm stuck when trying to create one of these things.
Here's my snippet:
<xsl:template match="/">
<div style="padding:7px;margin-right: 10px; margin-bottom: 15px;">
<a href="{//macro/selectedMedia/node/data [@alias='umbracoFile']}" rel='lightbox' title="{//macro/selectedMedia/node/@nodeName}">
<img>
<xsl:attribute name="src">/umbraco/imageGen.aspx?image=<xsl:value-of select="//macro/selectedMedia/node/data [@alias='umbracoFile']" />&width=230&height=115&constrain=true</xsl:attribute>
<xsl:attribute name="class">reflect rheight25 ropacity35</xsl:attribute>
<xsl:attribute name ="style">border:none;</xsl:attribute>
</img>
</a>
</div>
</xsl:template>
I based the XPath from a blurb I saw somewhere on the web but it was written for Umbraco 3 - either I completely misunderstood the XML structure or something has changed from Umbraco 3 to 4. Can someone please help me get the correct XPath to obtain the umbracoFile value?
Many thanks,
Dany.
Dany,
Your code looks right and I pasted it directly to one of my macros using the macro parameter name and type and it appeared just fine.
Try adding ?umbDebug=true to the end of the page address to see what the macro is passing you. The only case it might not show up is if a Folder is selected vs and image, and so there would be no file. umbDebug should be able to show you the exact data passed.
-Chris
Thanks Chris - I will give that a try. I take it you created a parameter with selectedMedia alias of the mediaCurrent type? On my site it simply returned a "Hello World" image. I'm guessing that's the default image when the real one cannot be found?
D.
Interesting - here's the error I get:
Could not write XML node (selectedMedia)
Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at umbraco.macro.addMacroXmlNode(XmlDocument umbracoXML, XmlDocument macroXML, String macroPropertyAlias, String macroPropertyType, String macroPropertyValue)
at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
It seems to have a problem generating the XML in the first place I'm guessing - I'm not sure what I have done differently from you, Chris.
Interesting - here's the error I get:
Could not write XML node (selectedMedia)
Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at umbraco.macro.addMacroXmlNode(XmlDocument umbracoXML, XmlDocument macroXML, String macroPropertyAlias, String macroPropertyType, String macroPropertyValue)
at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
It seems to have a problem generating the XML in the first place I'm guessing - I'm not sure what I have done differently from you, Chris. Here's the output of Visualize XSLT tool:
<DIV style="PADDING-BOTTOM: 7px; PADDING-LEFT: 7px; PADDING-RIGHT: 7px; MARGIN-BOTTOM: 15px; MARGIN-RIGHT: 10px; PADDING-TOP: 7px"><A title="" href="" rel=lightbox><IMG style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none" class="reflect rheight25 ropacity35" src="/umbraco/imageGen.aspx?image=&width=230&height=115&constrain=true"></A></DIV>
It seems to have not inserted the appropriate image value for imageGen at all. Can you please clarify this is how I should use this macro?
Create a new node, and in the editor I insert this macro, and select the appropriate Media node/item as the selectedMedia value - that's all, right?
Dany,
I glanced at the umbraco source code and it looks like there is being thrown while looping through the macro properties trying to generate the xml node. Which makes me think something happened while creating the macro, in the macros section not inserting it on the page.
In the Macros section try removing the parameter 'selectedMedia' from the macro and saving the macro, then add the parameter back in and save. Hopefully this will re-create the macro parameter correctly this time, which for whatever reason it didn't last time.
Also go back to your node and re-insert the macro just to be safe.
If that doesn't work try recreating the macro completely, but you can use the same XSLT file.
-Chris
Hi Chris, I have recreated a new Macro, with a new name, but the same parameter name and the same XSLT. Unfortunately it's still not working. I'm really stumped about this - it seems simple enough.
On the Parameters tab in the Macro's dashboard, what does the "Show" tickbox do? If you have a spare moment can you possibly outline the steps you took in creating each item from XSLT, Macro, and new Content node? My new content node is just a simple Document type with two data fields, one with alias "heading" (text string) and another with alias "bodyText" (Richtext). The macro is inserted into the bodyText field.
Can you think of any potential source of problems in these steps? I think bodyText may be a reserved Umbraco field name, like umbracoFile or some such, isn't it? Can that be a problem?
Cheers,
D.
As with the other problem I posted previously, one which used umbracoRedirectId, this feels like some weird caching issue. When I started up my VM again this morning it all worked just fine.
If anyone is interested in a macro to insert a thumbnail which opens up the image in a lightbox here it is:
<xsl:template match="/">
<xsl:variable name="imageSrc" select="//macro/imageFile/node/data [@alias='umbracoFile']" />
<xsl:variable name="imageTitle" select="//macro/imageFile/node/@nodeName" />
<xsl:variable name="thumbWidth" select="//macro/thumbWidth" />
<xsl:variable name="imageWidth" select="//macro/imageWidth" />
<div style="padding:7px;border: 1px dotted #ddd; margin-right: 10px; margin-bottom: 15px;">
<a>
<xsl:attribute name="href">/umbraco/imageGen.aspx?image=<xsl:value-of select="$imageSrc"/>&width=<xsl:value-of select="$imageWidth" />&constrain=true</xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="$imageTitle" /> </xsl:attribute>
<xsl:attribute name="rel">lightbox</xsl:attribute>
<img>
<xsl:attribute name="src">/umbraco/imageGen.aspx?image=<xsl:value-of select="$imageSrc"/>&width=<xsl:value-of select="$thumbWidth" />&constrain=true</xsl:attribute>
<xsl:attribute name="class">reflect rheight25 ropacity35</xsl:attribute>
<xsl:attribute name ="style">border:none;</xsl:attribute>
</img>
</a>
</div>
</xsl:template>
The macro associated to this XSLT needs the four parameters to be read into the four variables above. Nothing magical here - very simple macro.
Thanks for all your help Chris.
Chris Dunn -
Don't know if you helped the original request, but you definitely helped me solve my problem.
Thanks,
C
is working on a reply...