Interesting question, instead of using a Razor macro in v6 you can use a macro partial view. Although under the hood this is a Mvc partial, in Umbraco it is just a macro so can be used in a webforms template in the same way as a Razor macro. At some point Razor macros will be retired in favour of using the macro parial view for webforms. of course if you are using Mvc templating then you already have all the new Razor available.
So in Mvc or by using a Macro partial view you have access to the new Published Content and Umbraco helper rather than DynamicNode and Published Content is a lot better and faster! Take a look at the Mvc documentation for some more info.
Now just add the macro to your template as you would normally with a Razor macro and it should render. Now you can use the new Published Content objects in your macro!
GetType Dynamic Null in macro still applicable?
Hi we're using 6.0.3 I'm just wondering when writing macro's in razor do we really still have to be doing queries like:
var tabbedContentItems = Model.Children.Where("NodeTypeAlias == @0 && Visible", "TabbedContentItem");
and then dealing with DynamicNulls and or DynamicNode comparison?
i.e. @if (eventContainer.GetType() != typeof(DynamicNull) && eventContainer.Children.Where(c => c.Visible && c.HasValue("eventEndDate") && c.GetProperty<DateTime>("eventEndDate") >= DateTime.Now).Any())
The razor view stuff is awesome but coding in macro's still feels like 4.7.. is there a suggested way of moving forward code wise?
Cheers,
Tom
Hi Tom,
Interesting question, instead of using a Razor macro in v6 you can use a macro partial view. Although under the hood this is a Mvc partial, in Umbraco it is just a macro so can be used in a webforms template in the same way as a Razor macro. At some point Razor macros will be retired in favour of using the macro parial view for webforms. of course if you are using Mvc templating then you already have all the new Razor available.
So in Mvc or by using a Macro partial view you have access to the new Published Content and Umbraco helper rather than DynamicNode and Published Content is a lot better and faster! Take a look at the Mvc documentation for some more info.
Jeavon
Thanks Jeavon,
Unforunately I need to use it in both razor views and some legacy master page templates for a period of time hence why it needs to be a macro..
Thanks,
Tom
Hi Tom,
A "Partial View Macro" is just a macro the same as a razor or xslt macro so you can use them in your webforms templates in exactly the same way.
Thanks,
Jeavon
Hi Jeavon,
Thanks for the replies.. where in the documentation is anything on partial view macros? I can't find anything in the mvc section..
I'm using a macro with a cshtml file at the moment and that's where I'm running in to a world of old umbraco pains
Hi Tom,
I don't think there is any yet :-(
Just create a new "Partial View Macro File" in the developer tree and leave the "Create Macro" ticked. As a very simple example try this in the file:
Now just add the macro to your template as you would normally with a Razor macro and it should render. Now you can use the new Published Content objects in your macro!
Jeavon
is working on a reply...