Copied to clipboard

Flag this post as spam?

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


  • julius 107 posts 289 karma points
    Nov 28, 2011 @ 23:46
    julius
    0

    Macro content not showing up. Need workaround

    Hi,

    I use a macro to display the "body" field of "Article" nodes. This macro adds an Adsense advertisement to the body text before it is displayed.

    I created another .NET macro that is used inline in the Rich Text Editor that editors use to work on the body text. It allows the editor to specify a video file that is then displayed in the page.

    This combination doesn't work. The output of the inline macro is not shown, seemingly because the body field itself is processed by a macro. It's a macro within a macro! When I use the <umbraco:item> tag to display the body field, than the video is shown, but than of course, the Adsense ad is not added to the body text.

    Is there a way in which I can both render the body field with a macro AND display the inline video macro or is this not possible?

  • Nigel Wilson 944 posts 2076 karma points
    Nov 29, 2011 @ 00:43
    Nigel Wilson
    1

    Hi Julius

    If I have read your post correctly you could try the following in an xslt file:

    <xsl:value-of select="umbraco.library:RenderMacroContent($currentPage/bodyText, $currentPage/@id)" disable-output-escaping="yes"/>

    This enables the rendering of macros within macros.

    Cheers

    Nigel

  • julius 107 posts 289 karma points
    Nov 29, 2011 @ 01:06
    julius
    1

    Hey Nigel,

    I indeed found the RenderMacroContent function. I am using .NET and solved the problem as follows.

    // Renders inline macro's on RTE fields that are themselves processed by a macro
            public string RenderInlineMacros(string articleBody)
            {
                return RecursiveMacroLookupAndReplace(articleBody);
            }
    
            private string RecursiveMacroLookupAndReplace(string input)
            {
                // Find the start point of the first inline macro
                int start = input.IndexOf("<?UMBRACO_MACRO");
                if (start > 0)
                {
                    // Find the endpoint of the first inline macro
                    int end = input.IndexOf("/>", start) + 2;
                    // Extract the inline macro statement
                    string macroStatement = input.Substring(start, end - start);
                    // Replace the macro statement with its output
                    input = input.Replace(macroStatement, library.RenderMacroContent(macroStatement, Node.getCurrentNodeId()));
                }else
                {   
                    // No more macro statements? Return the result.
                    return input;
                }
                // Look for more macro statements recursively.
                return RecursiveMacroLookupAndReplace(input);
            }
Please Sign in or register to post replies

Write your reply to:

Draft