Copied to clipboard

Flag this post as spam?

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


  • Tom 120 posts 448 karma points
    Feb 27, 2014 @ 21:11
    Tom
    0

    Rendering Macros From Macro Container MVC

    Hey

    I'm trying to display a simple macro, which has been chosen in a macro container.

    When using @Umbraco.Field("macroPicker") the output to the html is:

    < ! --?UMBRACO_MACRO macroAlias="SearchForm" /-->

    How do I render macros from the Macro Container?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 28, 2014 @ 08:04
    Dennis Aaen
    0

    Hi Tom

    You could try something like this:

    @Html.Partial("searchForm");

    The documentation about this can you find here: http://our.umbraco.org/documentation/Reference/Mvc/partial-views

    Hope this helps,

    /Dennis

  • Tom 120 posts 448 karma points
    Feb 28, 2014 @ 08:09
    Tom
    0

    Hey Dennis - thanks for the reply.

    I'm not just trying to render a macro. I'm trying to render a list of macros, which has been selected in a Macro Container property editor.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 28, 2014 @ 09:12
    Dennis Aaen
    0

    Hi Tom,

    I just searched the web, for trying to help you further, and I found a relativly new blogpost from the22 Feb 14 about usingmacro-container in MVC. Maybe this can help you further.

    http://sam-mullins.com/articles/how-i-hack-the-macro-container-into-working-with-mvc/

    /Dennis

  • Tom 120 posts 448 karma points
    Feb 28, 2014 @ 09:16
    Tom
    0

    Thanks again - I've already seen that post and I'm having a hard time believing that all this is necessary. Kind of defeats the point of the Macro Container...

  • Fengelz 106 posts 221 karma points
    Mar 17, 2014 @ 11:26
    Fengelz
    101

    Hi Tom. 

    Maybe you have solved your problem by now, if not though, here's how I fixed it in Umbraco 7.

    @Html.Raw(umbraco.library.RenderMacroContent(CurrentPage.textColumns, CurrentPage.Id))

    Using the old umbraco.library which is still available. You can pass a macro text string and a pageid(mandatory) and it will render your macro container for you.

    Hth 

    - Sune

  • Tom 120 posts 448 karma points
    Mar 17, 2014 @ 11:59
    Tom
    0

    Thanks alot, I'll try that.

  • Vincent Baaij 95 posts 344 karma points c-trib
    Mar 17, 2014 @ 14:40
    Vincent Baaij
    1

    Tom,

    In my (6.1.6) application a Macro Container is used on a field in a DocumentType. The field is rendered in the MVC template with the following statement:

    @Umbraco.Field("headerSection", recursive: true)

    (In case you're wondering: the recursive part searches up the content tree until it finds a field with that alias)

  • Michael 63 posts 211 karma points
    Jun 11, 2014 @ 12:34
    Michael
    0

    Hi guys

    I am currently working on a problem like this in Umbraco 7.1.4.

    My site structure looks like this:

    Danish company name (homepage doctype)
    - Subpages
    Language version folder
    - English version (called EN, also homepage doctype)
    -- Subpages

    The idea is that the webmaster manually inserts the menu on each new language he creates. With a macrocontainer, with the alias indsaetMenu, placed on the homepage doctype.

    Using the:

    @Html.Raw(umbraco.library.RenderMacroContent(CurrentPage.indsaetMenu, CurrentPage.Id))

    The menu renders on the frontpage, but when I navigate to a subpage the menu is gone. So my question is how do I rewrite it so it does not rely on currentpage? Or mabye it's just missing some recursive function?

    Any ideas? :)

     

    /Michael

     

  • Damian Chambers 23 posts 87 karma points
    Jan 18, 2017 @ 15:16
    Damian Chambers
    0

    This works for me:

    @Umbraco.RenderMacro("NameofMacro", new { Parameter = CurrentPage.Property})

  • 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