Copied to clipboard

Flag this post as spam?

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


  • Rob Walker 13 posts 34 karma points
    Dec 21, 2012 @ 10:49
    Rob Walker
    0

    macro in a macro

    Apologies first if this thread should have gone under templates.  I need to frig a template to have a macro in a macro.  Can anyone assist?  Code example below:

    <umbraco:Macro runat="server" language="cshtml"> 

    @{

    if(@Request.QueryString["ref"] == "20121338")

    {

    <umbraco:Macro MediaID="29259" Alias="DisplayMediaItem" runat="server"></umbraco:Macro>

    }

    }                                                                                                                             

    </umbraco:Macro>

    I appreciate this is dirty but I need a quick fix to buy me time to re-write the full macro.

     

    Regards,

    Rob

  • Jonas Eriksson 930 posts 1825 karma points
    Dec 21, 2012 @ 11:11
    Jonas Eriksson
    0

    Hi

    what kind of a macro are we talking about ? You can use RenderPage http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/@renderpage-with-args or umbraco.RenderMacro http://our.umbraco.org/documentation/v501/reference/templating/umbraco-helpers/umbraco_rendermacro (but not if it's an ascx)

  • Jonas Eriksson 930 posts 1825 karma points
    Dec 21, 2012 @ 11:13
  • Rob Walker 13 posts 34 karma points
    Dec 21, 2012 @ 11:13
    Rob Walker
    0

    its a cshtml macro

  • Rob Walker 13 posts 34 karma points
    Dec 21, 2012 @ 11:18
    Rob Walker
    0

    no joy on changing the encoding (unless i've done a school boy error).  example below:

     

    <umbraco:Macro runat="server" language="cshtml">  

    @{

    if(@Request.QueryString["ref"] == "20121338")

    {

    &lt;?UMBRACO_MACRO macroAlias=&quot;DisplayMediaItem&quot; MediaID=&quot;29259&quot;&gt;&lt;/?UMBRACO_MACRO&gt;

     

     

    <h1>test 1</h1>

    }

    else

    {

    <h2>test 2</h2>

    }

    }

    </umbraco:Macro>

  • Gaitano Boeraeve 17 posts 56 karma points
    Dec 21, 2012 @ 12:55
    Gaitano Boeraeve
    0

    I recognise the problem you're describing. 
    In a lot of my project I use MNTP to select blocks ( = macrofile renders it's content).
    When I insert a macro in the RTE of that block I had the same problem you describe.

    Like said above, RenderMacroContent is the solution for this problem. Have a look at my code snippet:

    SelectedContentRight are my selected blocks. Hope this helps.

        @foreach (var node in selectedContentRight)
        {
            var elementHtml = RenderPage(GetMacro(node), node);
            @(Html.Raw(umbraco.library.RenderMacroContent(elementHtml.ToString(), Model.Id)))
        }
  • 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