Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Jul 16, 2013 @ 08:37
    Tom
    0

    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

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 16, 2013 @ 10:00
    Jeavon Leopold
    0

    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

  • Tom 713 posts 954 karma points
    Jul 18, 2013 @ 01:17
    Tom
    0

    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

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 18, 2013 @ 22:35
    Jeavon Leopold
    0

    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

  • Tom 713 posts 954 karma points
    Jul 19, 2013 @ 00:27
    Tom
    0

    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

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 19, 2013 @ 14:00
    Jeavon Leopold
    0

    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:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        foreach (IPublishedContent page in Model.Content.AncestorOrSelf().Children)
        {
            <p>@page.Name</p>
        }  
    }

     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

Please Sign in or register to post replies

Write your reply to:

Draft