Copied to clipboard

Flag this post as spam?

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


  • TENNO 13 posts 73 karma points
    Nov 08, 2013 @ 18:00
    TENNO
    0

    Invoke umbraco:Macro inside Razor

    Hi,

    I want to call XSLTsearch macro inside razor code.

    The reason is:

    I want to make the search results based on the culture

    so, it should be something Like that:

    @if (Culture == "en-US")
    {
        <form>
            <umbraco:Macro runat="server" Alias="XSLTsearch"
                // setting some parameters "not based on the condition"
    
                // This Parameters based on condition result
                searchFields="titleText_en, bodyText_en"
                previewFields="titleText_en, bodyText_en">
            </umbraco:Macro>
        </form>
    }
    else
    {
        <form>
            <umbraco:Macro runat="server" Alias="XSLTsearch"
                // setting some parameters "not based on the condition"
    
                // This Parameters based on condition result
                searchFields="titleText, bodyText"
                previewFields="titleText, bodyText">
            </umbraco:Macro>
        </form>
    }
    

    -

    Thanks in advance!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 10, 2013 @ 21:11
    Jeavon Leopold
    0

    Hi,

    It depends on if you are using MVC Razor (View, Partial View, Macro Partial View) or a legacy Razor Macro (DynamicNode).

    For MVC, you can render any Macro from the Macro Engine with something similar to:

    @Umbraco.RenderMacro("myMacroAlias", new { name = "Ned", age = 28 })
    

    Full documentation here

    For a legacy Razor Macro, you need to do something similar to this:

    @(Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"myMacroAlias\" ></?UMBRACO_MACRO>", Model.Id)))
    

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft