I am trying to get the macro container to work inside a razor macro but all i get is a string container the old macro tag "<umbraco:macro..... " and i cant seem to find a helper method for rendering the output of that macro. IS it even poseble to do with the current support for razor ? Or do i need to make a helper method that renders the "old macro" and the returns the rendered html ?
@Umbraco.Field("youfieldhere") works for me but as soon as I put anything in my macro that's dynamic I get the error "Error loading Partial View script" What do I need to put in my Partial to get it to inherit from the right View?
if I render my partial directly it works. @if (Model.Content.HasValue("macroPicker", true)){ @Umbraco.Field("macroPicker") // doesnt work if partial contains anything dynamic @Html.Partial("my-partial-name") // works }
what to do to get this to work or get a decent error message?
@if (Model.Content.HasValue("macroPicker", true)){ var partialName = Umbraco.Field("macroPicker").ToString(); var trimmedPartialName = partialName.Substring(63, partialName.Length - 71); // trimming the string to get just the macro name @Html.Partial(trimmedPartialName) }
Razor and Macro Container
Hey ppl
I am trying to get the macro container to work inside a razor macro but all i get is a string container the old macro tag "<umbraco:macro..... " and i cant seem to find a helper method for rendering the output of that macro. IS it even poseble to do with the current support for razor ? Or do i need to make a helper method that renders the "old macro" and the returns the rendered html ?
any ideas ?
//Troels
If the macro you are trying to use in the container is razor, you can try
arrParams is an optional parameter to allow you to pass data into the razor macro.
There is some more info in the wiki: http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/@renderpage-with-args
I also found this page useful for learning about ways to structure razor code.
http://joeriks.com/2011/03/11/better-structure-for-your-razor-scripts-with-renderpage-in-umbraco/
Troels,
until now i still have not found a (the?) way to render a macro container using razor. This is the only thing I still use XSLT for.
How did you solved your issue?
Kind regards
Hey Damiaan
if u are using razor and master pages (4.7 way) i used <umbraco:Item field="macroContainer" />
if u are 4.10 + and use mvc u can use the @Umbraco.Field()
@Umbraco.Field("youfieldhere") works for me but as soon as I put anything in my macro that's dynamic I get the error "Error loading Partial View script"
What do I need to put in my Partial to get it to inherit from the right View?
if I render my partial directly it works.
@if (Model.Content.HasValue("macroPicker", true)){
@Umbraco.Field("macroPicker") // doesnt work if partial contains anything dynamic
@Html.Partial("my-partial-name") // works
}
what to do to get this to work or get a decent error message?
I got it working with the following horrible hack
How's it meant to be done properly?
Ah, ok aswering my own question here
put the following in you macro partial at the top
rather than the usual @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@wolulcmit - did you ever find a proper way?
@Html.Raw( Model.Content.GetPropertyValue("macroPicker") )
is working on a reply...