Copied to clipboard

Flag this post as spam?

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


  • bev0 39 posts 59 karma points
    Dec 08, 2010 @ 18:07
    bev0
    0

    how to call a macro in a template using .net

    i'm using umbraco 4.5, i need to do a .net inline Response.Redirect in a template. i have a macro that return a string which is an URL. the Response.Redirect will pick up that URL string and work upon it.

    my current problem is, i can't call the macro using .net code, here is what i have so far.

    <%
    lImgUri = umbraco.library.RenderMacroContent("<umbraco:Macro Alias="" macroAlias=""FilmMediaImage"" runat=""server""></umbraco:Macro>", lPageId)
    %>

    the above line used to work in umbraco 4.0 but in 4.5 it stopped working. it can be as easy as some syntax change on that line but i can't seem to figure it out.

    any comment/suggestion/advice will be utmost appreciated! please help

     

     

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Dec 08, 2010 @ 18:58
    Anthony Dang
    0

    I've never done it like that. I normally use an extension method.

    Try this:

     

            public static string RenderMacroContent(int nodeId, string field)
            {
                Item item = new Item();
                item.Field = field;
                item.NodeId = nodeId.ToString();
    
                string s = umbraco.library.RenderMacroContent((string)item.PageElements[field], nodeId);
                return s;
            }
    

     

    Update: this is actually what I use to render a macro which is in a WYSIWYG.

     

  • bev0 39 posts 59 karma points
    Dec 08, 2010 @ 21:12
    bev0
    0

    i translate what you suggested as:
    lImgUri umbraco.library.RenderMacroContent(DirectCast("<umbraco:Macro Alias='FilmMediaImage' macroAlias='FilmMediaImage' runat='server' />"String)lPageId)  

    and it's still not working.
    could you please paste me the line where you apply the macro into, the part where you add <umbraco:macro.... />

    thanks!

     

Please Sign in or register to post replies

Write your reply to:

Draft