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?
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 macropublicstring RenderInlineMacros(string articleBody)
{
return RecursiveMacroLookupAndReplace(articleBody);
}
privatestring RecursiveMacroLookupAndReplace(string input)
{
// Find the start point of the first inline macroint start = input.IndexOf("<?UMBRACO_MACRO");
if (start > 0)
{
// Find the endpoint of the first inline macroint end = input.IndexOf("/>", start) + 2;
// Extract the inline macro statementstring 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);
}
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?
Hi Julius
If I have read your post correctly you could try the following in an xslt file:
This enables the rendering of macros within macros.
Cheers
Nigel
Hey Nigel,
I indeed found the RenderMacroContent function. I am using .NET and solved the problem as follows.
is working on a reply...