Copied to clipboard

Flag this post as spam?

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


  • [email protected] 30 posts 42 karma points
    Nov 04, 2009 @ 17:43
    r_lamb@hotmail.com
    0

    Need help with very simple xslt to use in editor

    I'm starting very simple here, I've created a xslt that does this:

    <xsl:template match="/"> <!-- start writing XSLT --> <span style="color: red"> Hello </span> </xsl:template>

    I started with a clean xslt and had it create the macro for me. Now when I insert this into the editor, I expect to see "Hello" in red in the editor and on the page when rendered. I can't get it to show anything in either place. I've checked both box's to use in editor and render content. I've actually written a number of xslt that have worked great when called from my template, but have yet to get one to work in the editor. What's my problem? Please help! Thanks!

  • Richard 146 posts 168 karma points
    Nov 04, 2009 @ 18:46
    Richard
    0

    I would recommend from experience not to insert macros into text fields, as at least in older versions of Umbraco (pre version 4) the calls would sometimes get corrupted and stop working but a bigger issue is someone accidentally deleting the macro call while updating the page content. You can pass values from the text and settings from the page through the macro call to the template.

  • [email protected] 30 posts 42 karma points
    Nov 04, 2009 @ 19:30
    r_lamb@hotmail.com
    0

    I think I figured out what the problem is on this. The macro is not rendering because the content is nested in another parent macro/xslt call. So the parent macro is trying to render content that also has a nested macro and I'm guessing this is not possible. Can anyone confirm?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 04, 2009 @ 21:06
    Kim Andersen
    0

    Yeah you are right r_lamb.

    If you use xslt to render your content-field, then you can use one of the build in umbraco extensions. If you have a richtext editor with an alias of "content", you can use the below code to render the content including the inserted macro:

    <xsl:variable name="myContent" select="$currentPage/data[@alias='content']"/>
    <xsl:value-of select="umbraco.library:RenderMacroContent($myContent, $currentPage/@id)" disable-output-escaping="yes"/>

     

    Hope this fixes your problem :)

     

    /Kim

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Nov 04, 2009 @ 21:18
    Chriztian Steinmeier
    0

    I remember having managed to get macros in editor fields that were themselves rendered from a macro to work, which involved a recursive template — something along the following steps:

    1. Render all content before the (1st) macro
    2. Extract the macro markup and pass that on to the library function RenderMacroContent()
    3. Do it again with the remaining content, checking for more macros...

    I'll try to find the actual code if anyone's interested...

    /Chriztian 

  • [email protected] 30 posts 42 karma points
    Nov 05, 2009 @ 15:32
    r_lamb@hotmail.com
    0

    Kim, your code worked. Thanks allot! It will be helpful to have this as an option and worked great for my specific need. 

    Chriztian - Thanks for you info as well. Looks like a good approach if you have multiple nested macros (more then one level deep). Thankfully that is not the case for me right now but I will keep that idea in my back pocket.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 05, 2009 @ 21:18
    Kim Andersen
    0

    You are welcome :)

     

    Remember to mark this post as answered ;)

Please Sign in or register to post replies

Write your reply to:

Draft