Copied to clipboard

Flag this post as spam?

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


  • Roger Withnell 128 posts 613 karma points
    Dec 05, 2015 @ 14:27
    Roger Withnell
    0

    Render a macro from a macro container with MVC Razor

    I have a macro that renders correctly with

    @Umbraco.RenderMacro("pictureSlider")
    

    in the template.

    Now, I want the to choose a macro by using the Macro Container. My document type has the property with the Macro Container data type. In the page I select the "pictureSlider" macro.

    But now what is the code to render the "pictureSlider" macro on the page?

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Dec 06, 2015 @ 15:05
    Dennis Aaen
    100

    Hi Roger,

    Try to use this snippet of code if you are running dynamic Razor

    @Html.Raw(CurrentPage.macroContainer)
    

    If you are using strongly typed Razor, you should use this syntax

    @Html.Raw(Model.Content.GetPropertyValue("macroContainer") )
    

    Remember to change the "macroContainer" so it match your property alias on your document type.

    Hope this helps,

    /Dennis

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Apr 05, 2017 @ 07:29
    Bjarne Fyrstenborg
    0

    Hi Dennis

    Do you know how to render a Umbraco Forms picker via macro container using ModelsBuilder.

    I have tried the following without any luck - actually Model.Content.Form doesn't seem to return a value for the picked macro container.

    @Html.Raw(Model.Content.Form)
    

    However this does work:

    @Html.Raw(Model.Content.GetPropertyValue("form"))
    

    /Bjarne

  • Rune Antonsen 29 posts 145 karma points
    Apr 12, 2017 @ 09:59
    Rune Antonsen
    0

    I have the same issue. I just ended up turning it into something strongly typed:

    @Html.Raw(Model.Content.GetPropertyValue(FormsViewer.GetModelPropertyType(x => x.UmbracoForm).PropertyTypeAlias))
    

    Where FormsViewer is the ModelsBuilder generated class and UmbracoForm is the Property.

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Apr 12, 2017 @ 10:20
    Bjarne Fyrstenborg
    0

    In my case it was actually a bug on Umbraco Cloud / in Courier, because I had renamed the property alias on the composition, but after deploy of the changes, live environment still had the old alias. http://issues.umbraco.org/issue/UAAS-493

    So I ended up with the following:

    @{
        Guid g = new Guid(Model.Content.FormPicker.ToString());
        Html.RenderAction("Render", "UmbracoForms", new { formId = g, mode = "form" });
    }
    
  • Roger Withnell 128 posts 613 karma points
    Dec 06, 2015 @ 15:42
    Roger Withnell
    0

    Thanks, Dennis.

    That's fixed it!

    Thanks to you guys, I'm having a good weekend.

    Roger

Please Sign in or register to post replies

Write your reply to:

Draft