Copied to clipboard

Flag this post as spam?

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


  • Simon Goldsmith 14 posts 33 karma points
    Nov 12, 2013 @ 10:26
    Simon Goldsmith
    0

    Is this template code or macro code?

    I am fairly new to Umbraco and Razor, and I keep seeing snippets of code like this which I have tried to use, but do not understand whether it is code that can should be placed in a template, partial view, macro? I'd be grateful if someone could explain as I either get error messages telling me @Model cannot be used or the @inherits line is not allowed etc.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    enter code here`@{
        var last = Model.DescendantsOrSelf().Last();
    
        if (last != null && Model.Id != last.Id)
        {
            Response.Redirect(last.Url);
        }
    }
    

    Thanks Simon

  • Dan Lister 416 posts 1974 karma points c-trib
    Nov 12, 2013 @ 11:03
    Dan Lister
    0

    Hi Simon. Going off the top namespace, I'd say that looks like a Macro Partial. There's more information about Macro Razor scripts in the documentation section. Thanks, Dan.

  • Simon Goldsmith 14 posts 33 karma points
    Nov 12, 2013 @ 12:45
    Simon Goldsmith
    0

    Awesome thanks Dan. I thought it was Partial View Macro code.

    When I create a partial view macro via Umbraco backend it uses this

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    Can I just replace this line with this line:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    

    Is this ok to do as you can only inherit from on library etc?

Please Sign in or register to post replies

Write your reply to:

Draft