I'm trying to create a Document Type and matching template with a texstring that I can use to specify a macro, however this does not seem to work. I tried downloading the Macro Picker package which doesn't work either, I have double checked the XSLT file and it is working correctly. Has anyone done anything like this?
The a method in umbraco.library.RenderMacrocontent that'll render an macro that has a xslt file attached, but not a macro with a usercontrol attached. This method requires that the macroname is provided as an HtmlEncoded string of the code you would insert in a template, and as far as I know, it also requires that you use v3 template syntax. So I wouldn't recommend using this approach.
Can you tell us a bit more what it is you're trying to achieve, I'm pretty sure theres another more easy way to do what you want.
Sure, I have a template on which I create content, a document type in which I am trying to specify either the name of the macro in a textstring or using the macro picker, neither methods work. The reason I'm trying to do this is so I can have 1 template, but many different contents, which can specify an XSLT which in turn show different feeds of content from the content section.
Sounds complicated but it really isn't, and hopefully it makes sense?
To test the library method Jesper mentioned, try this inside your general macro XSLT:
<!-- Grab the name of the macro to render -->
<xsl:variable name="macroAlias" select="$currentPage/data[@alias = 'macroFeed']" />
...
<!-- Render macro here -->
<xsl:value-of select="umbraco.library:RenderMacroContent('<?UMBRACO_MACRO macroAlias="{$macroAlias}" />', $currentPage/@id)" disable-output-escaping="yes" />
I think we're close, but not there yet, that code produced the following output:
This page contains the following errors:
error on line 1 at column 165: Extra content at the end of the document
Below is a rendering of the page up to the first error.
<Macro: (,)>
I commented out the RenderMacroComment line and just output the variable and it is picking up the value from the content page, just looks like there's a small error with the above line.
This last error you're getting is very likely to come from the "EventsFeed" macro - does it require a node id or something? It's the sort of error you'd get when calling GetMedia() or GetXmlNodeById() with an empty variable...
I'll leave this for now and just create templates for each of the feeds that we need, as time is pressing on. I will try to return to it at a later date.
Just in case you make it back to this (and for others getting here for an answer): I've been testing this myself now, and there's a silly error in the code snippet I wrote earlier today - this snippet actually works:
<!-- Grab the name of the macro to render -->
<xsl:variable name="macroAlias" select="$currentPage/data[@alias = 'macroFeed']" />
...
<!-- Render macro here -->
<xsl:value-of select="umbraco.library:RenderMacroContent(concat('<?UMBRACO_MACRO macroAlias="', $macroAlias, '" />'), $currentPage/@id)" disable-output-escaping="yes" />
For those who'd like to know why this works and the other don't, here's the explanation:
Attribute Value Templates (the curly-brackets) are not evaluated inside the select attribute on a variable (or param), so the method-call ended up asking for the macro with the alias {$macroAlias} which, obviously, didn't exist. Using concat() instead, will do the trick. If you're still reading: Yay! You like XSLT :-)
Reusable Document Type with Macro Source
Hi all,
I'm trying to create a Document Type and matching template with a texstring that I can use to specify a macro, however this does not seem to work. I tried downloading the Macro Picker package which doesn't work either, I have double checked the XSLT file and it is working correctly. Has anyone done anything like this?
Regards,
Darryl
The a method in umbraco.library.RenderMacrocontent that'll render an macro that has a xslt file attached, but not a macro with a usercontrol attached. This method requires that the macroname is provided as an HtmlEncoded string of the code you would insert in a template, and as far as I know, it also requires that you use v3 template syntax. So I wouldn't recommend using this approach.
Can you tell us a bit more what it is you're trying to achieve, I'm pretty sure theres another more easy way to do what you want.
Regards
Jesper Hauge
Hi Jesper,
Sure, I have a template on which I create content, a document type in which I am trying to specify either the name of the macro in a textstring or using the macro picker, neither methods work. The reason I'm trying to do this is so I can have 1 template, but many different contents, which can specify an XSLT which in turn show different feeds of content from the content section.
Sounds complicated but it really isn't, and hopefully it makes sense?
Regards,
Darryl
To simplify, I would like to specify the macro name in a textstring document type instead of adding in the macro in the template...
This doesn't work either:
With macroFeed being the name of the property in the document type.
Hi Darryl,
To test the library method Jesper mentioned, try this inside your general macro XSLT:
/Chriztian
Hi Chriztian,
I think we're close, but not there yet, that code produced the following output:
I commented out the RenderMacroComment line and just output the variable and it is picking up the value from the content page, just looks like there's a small error with the above line.
Regards,
Darryl
Ok, tested this as well:
Which give this output:
Error parsing the XSLT:
System.OverflowException: Value was either too large or too small for an Int32.
Bit confused now...
Hi Darryl,
This last error you're getting is very likely to come from the "EventsFeed" macro - does it require a node id or something? It's the sort of error you'd get when calling GetMedia() or GetXmlNodeById() with an empty variable...
/CS
No, the EventFeed doesn't accept any parameters.
I'll leave this for now and just create templates for each of the feeds that we need, as time is pressing on. I will try to return to it at a later date.
Thanks for your help.
Hi again Darryl,
Just in case you make it back to this (and for others getting here for an answer): I've been testing this myself now, and there's a silly error in the code snippet I wrote earlier today - this snippet actually works:
For those who'd like to know why this works and the other don't, here's the explanation:
Attribute Value Templates (the curly-brackets) are not evaluated inside the select attribute on a variable (or param), so the method-call ended up asking for the macro with the alias {$macroAlias} which, obviously, didn't exist. Using concat() instead, will do the trick. If you're still reading: Yay! You like XSLT :-)
/Chriztian
is working on a reply...