1/ Don't think you need those quotes in NiceUrl('???'), as NiceUrl is expecting a number parameter.
2/ It won't hurt to use number($currentPage/data [@alias ='ctaLink']) as input to the NiceUrl function
3/ It won't save like that, be sure to surround the xsl:value-of with an xsl:if statement to check for valid input (Is required for saving - unless you'd check the 'ignore errors' checkbox)
One more question - is it possible to do this directly from the document template, bypassing the macro?
I am able to drop the page field into my template, getting the number (1051), but I haven't been able to wrap or convert that to the URL. Is this possible to do with inline xslt?
If it helps, the context I'm using this in is having a few selectable document properties (content pickers) which allow the editors to edit the pages a few buttons link to. If I Could do this directly from the template, instead of creating a macro for each one that would be nice.
Thanks for the suggestion. I checked, and I don't seem to have a redirect. I tried putting this same macro into another site which definitely had no redirect, and got the same error when trying to save.
From my basic testing, it seems to be having a problem with this line:
[code][/code]
if I change $button to '1051' the macro saves fine, but I need it to be dynamic.
If you save the xslt, it checks if its valid to the first node. If that node doesn't have the property you want, it gives an error like you have right now.
Adding an xsl:if statement to check if its empty should prevent the error though.
I hate to drag this back up, but I'd really like to understand this more completely.
I've added a similar thing to a different site today, and am again getting the same issue as before. I added the document type property to the topmost node template (homepage), and it didn't help on this site.
If I use this code:
I get no error on saving. If I do the same but without the xsl:if wrapper, again it saves fine.
As soon as I throw in my niceurl code, it throws the error on saving.
this also throws an error:
The macro is in a document template, which has no 'official' parent template. I'm using an ajax script to load this page into a div on the homepage, but there is no template or document type link between the two pages.
I'd really appreciate any more help in understanding why it's throwing the problem with niceurl.
Passing a document type property to NiceUrl in a macro? (syntax help)
I have a document property of type content picker, but I can't get the syntax right to access it in my macro.
The content picker is called ctaLink, and I need to access that in such a way that I can replace the three question marks in my code with this.
If I replace the ??? with the number ID of my content (1051) it works fine, I can't get it display it dynamically though.
[code]
My link
[/code]
I have tried creating a variable for the document property:
then putting $button in place of the ??? but it doesn't appear to be accessing the property.
Please could anyone point out where I'm going wrong?
Hi,
1/ Don't think you need those quotes in NiceUrl('???'), as NiceUrl is expecting a number parameter.
2/ It won't hurt to use number($currentPage/data [@alias ='ctaLink']) as input to the NiceUrl function
3/ It won't save like that, be sure to surround the xsl:value-of with an xsl:if statement to check for valid input (Is required for saving - unless you'd check the 'ignore errors' checkbox)
Other than that, I don't see syntactical errors.
Regards,
/Dirk
Thanks Dirk, that got it working nicely.
One more question - is it possible to do this directly from the document template, bypassing the macro?
I am able to drop the page field into my template, getting the number (1051), but I haven't been able to wrap or convert that to the URL. Is this possible to do with inline xslt?
If it helps, the context I'm using this in is having a few selectable document properties (content pickers) which allow the editors to edit the pages a few buttons link to. If I Could do this directly from the template, instead of creating a macro for each one that would be nice.
Thanks again for the help.
Hi,
Haven't done it yet myself, and can only think of using inline xslt in your template! It should work, but again, I haven't done nor verified it.
http://umbraco.org/documentation/books/inline-xslt
Regards,
/Dirk
Thanks again Dirk,
I have run into one small snag - it's not saving without errors. if I check 'ignore errors' it works ok.
I've also tried replacing the xsl:if string test with a number test, but same problem.
Here's my code (error is below). If it's obvious what I've got wrong that's stopping this saving, please could you point it out to me?
Thanks
[code]
]>
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">
[/code]
here's the error when I save:
(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Hi,
do you have an umbracoRedirect on the top-most node by any chance?
If so, that is causing the error.
HTH,
PeterD
Thanks for the suggestion. I checked, and I don't seem to have a redirect. I tried putting this same macro into another site which definitely had no redirect, and got the same error when trying to save.
From my basic testing, it seems to be having a problem with this line:
[code][/code]
if I change $button to '1051' the macro saves fine, but I need it to be dynamic.
Hi,
As I suggested a couple of posts before, add an xls:if statement arround the
Regards,
/Dirk
I did try that three different ways (separately), testing for an empty string, and trying it as a number:
I'm back again with the top-most node ;-)
Does that one have a property ctaLink?
Try to only to output the value of $button with
If that saves fine, you can extend the xslt again with more output.
HTH,
PeterD
Thanks,
the top-most node doesn't have a ctaLink property. I have only added that property to one document type (button-page).
By top-most node, do you mean the very top item (below content) in my content tree?
I dropped in just that line:
and removed all my other code (other than declaring the variable)
It still won't save though without throwing the error:
I also tried just this one line wrapped in the same xsl:if I tried before, but no difference.
I think I have found out something which is relevant:
I added the property to the template the top level node uses, in my case the homepage template.
Once I did that, the macro saves fine. However, I only want this property to be on one template, and not on the homepage.
Is there any way around this?
If you save the xslt, it checks if its valid to the first node. If that node doesn't have the property you want, it gives an error like you have right now.
Adding an xsl:if statement to check if its empty should prevent the error though.
This usually does the trick for me.
HTH,
PeterD
That's good to know for future reference.
Thanks for all your collective help & patience.
I hate to drag this back up, but I'd really like to understand this more completely.
I've added a similar thing to a different site today, and am again getting the same issue as before. I added the document type property to the topmost node template (homepage), and it didn't help on this site.
If I use this code:
I get no error on saving. If I do the same but without the xsl:if wrapper, again it saves fine.
As soon as I throw in my niceurl code, it throws the error on saving.
this also throws an error:
The macro is in a document template, which has no 'official' parent template. I'm using an ajax script to load this page into a div on the homepage, but there is no template or document type link between the two pages.
I'd really appreciate any more help in understanding why it's throwing the problem with niceurl.
is working on a reply...