I have a macro that renders reusable content. e.g. create a page, stick some content in it ("this is my reuseable content blah blah" then put a macro on another page and get it to render that reusable content.
So all well and good but if I want a macro inside my reusable content it gets commented out. Am guessing the parser is commenting it out for some reason, maybe because it would need to parse that macro and it can't do a double parse or something.
So was wondering if anyone had any ideas how to get my macro to be parsed inside the reusable content macro?
While this is not the best way of doing it, you should be able to call umbraco.library.RenderMacroContent(string RTEText, int nodeId) which will then render all content including macros from the RTE text specified.
Best practice though, is to split up macro dependencies to avoid things like these :-)
we thought about this kinda solution and were hoping their would be something more elegant but I guess we'll have to bite the bullet and do it this way, thanks for you time :-)
Using build-in functionality I use the following code
@Html.Raw(umbraco.library.RenderMacroContent("macroname", @CurrentPage.Id)) but i'm refactoring my code to not use this approuch anymore.
If i understand correctly you want to show information of one page anywhere in the content off another page. Can't you solve that by adding contentpicker to the page A to select page B or C and render certain properties on page A. This rendering can be done by using a macro with parameters. Where the parameters are the contentpickervalue and optional the attribute
Macros inside macros...
Hi,
I have a macro that renders reusable content. e.g. create a page, stick some content in it ("this is my reuseable content blah blah" then put a macro on another page and get it to render that reusable content.
So all well and good but if I want a macro inside my reusable content it gets commented out. Am guessing the parser is commenting it out for some reason, maybe because it would need to parse that macro and it can't do a double parse or something.
So was wondering if anyone had any ideas how to get my macro to be parsed inside the reusable content macro?
Hi CIG,
While this is not the best way of doing it, you should be able to call
umbraco.library.RenderMacroContent(string RTEText, int nodeId)
which will then render all content including macros from the RTE text specified.Best practice though, is to split up macro dependencies to avoid things like these :-)
/ Bo
Thanks Bo,
we thought about this kinda solution and were hoping their would be something more elegant but I guess we'll have to bite the bullet and do it this way, thanks for you time :-)
You can use the Razor Components package if you want to render a Razor Macro inside another Razor Macro.
Example:
Jeroen
Using build-in functionality I use the following code
@Html.Raw(umbraco.library.RenderMacroContent("macroname", @CurrentPage.Id)) but i'm refactoring my code to not use this approuch anymore.
If i understand correctly you want to show information of one page anywhere in the content off another page. Can't you solve that by adding contentpicker to the page A to select page B or C and render certain properties on page A. This rendering can be done by using a macro with parameters. Where the parameters are the contentpickervalue and optional the attribute
Just my cup of tea
G.
I think, if anything, the package that Jeroen links to is a more clean approach.
However, I think nesting of macros/partials should be avoided and code should be refactored instead to reduce dependencies.
/ Bo
is working on a reply...