Copied to clipboard

Flag this post as spam?

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


  • CIG 2 posts 22 karma points
    Sep 02, 2013 @ 16:28
    CIG
    0

    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?

     

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Sep 02, 2013 @ 22:25
    Bo Damgaard Mortensen
    0

    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

  • CIG 2 posts 22 karma points
    Sep 03, 2013 @ 11:34
    CIG
    0

    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 :-)

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 03, 2013 @ 12:05
    Jeroen Breuer
    0

    You can use the Razor Components package if you want to render a Razor Macro inside another Razor Macro.

    Example:

    @using Tocsoft.Umbraco.RazorComponents
    @Library.RenderMacro("MacroAlias", new { stringProp = "value", numberProp= 199, boolProp=true})
    @Library.RenderMacro("~/macroScripts/scriptFile.cshtml", new { Property1 = "value", Prop2= "value2"})

    Jeroen

  • Garret 63 posts 303 karma points
    Sep 05, 2013 @ 22:17
    Garret
    0

    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.

     

     

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Sep 05, 2013 @ 22:22
    Bo Damgaard Mortensen
    0

    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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies