Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Darryl Godden 145 posts 197 karma points
    Apr 12, 2010 @ 17:50
    Darryl Godden
    0

    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

  • Jesper Hauge 298 posts 487 karma points c-trib
    Apr 12, 2010 @ 21:28
    Jesper Hauge
    0

    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

  • Darryl Godden 145 posts 197 karma points
    Apr 13, 2010 @ 09:53
    Darryl Godden
    0

    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

  • Darryl Godden 145 posts 197 karma points
    Apr 13, 2010 @ 10:54
    Darryl Godden
    0

    To simplify, I would like to specify the macro name in a textstring document type instead of adding in the macro in the template...

  • Darryl Godden 145 posts 197 karma points
    Apr 13, 2010 @ 12:38
    Darryl Godden
    0

    This doesn't work either:

    <umbraco:Macro alias="[#macroFeed]" runat="server"></umbraco:Macro>

    With macroFeed being the name of the property in the document type.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 13, 2010 @ 12:46
    Chriztian Steinmeier
    0

    Hi Darryl,

    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('&lt;?UMBRACO_MACRO macroAlias=&quot;{$macroAlias}&quot; /&gt;', $currentPage/@id)" disable-output-escaping="yes" />

     

    /Chriztian

  • Darryl Godden 145 posts 197 karma points
    Apr 13, 2010 @ 13:30
    Darryl Godden
    0

    Hi Chriztian,

    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.

    Regards,

    Darryl

  • Darryl Godden 145 posts 197 karma points
    Apr 13, 2010 @ 13:36
    Darryl Godden
    0

    Ok, tested this as well:

    <xsl:variable name="macroAlias">EventsFeed</xsl:variable>
    
    <!-- Render macro here -->
    <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;{$macroAlias}&quot; /&gt;', $currentPage/@id)" disable-output-escaping="yes" />

    Which give this output:

    Error parsing the XSLT:

    System.OverflowException: Value was either too large or too small for an Int32. 

    Bit confused now...

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 13, 2010 @ 13:49
    Chriztian Steinmeier
    0

    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

  • Darryl Godden 145 posts 197 karma points
    Apr 13, 2010 @ 14:15
    Darryl Godden
    0

    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.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 13, 2010 @ 23:19
    Chriztian Steinmeier
    0

    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:

    <!-- 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('&lt;?UMBRACO_MACRO macroAlias=&quot;', $macroAlias, '&quot; /&gt;'), $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 :-)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft