Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 76 posts 166 karma points
    Jan 17, 2014 @ 13:49
    Nicky Christensen
    0

    get property recursive V.701

    Im trying to get some properties recursive (as on http://umbraco.com/follow-us/blog-archive/2011/9/15/umbraco-razor-feature-walkthrough%E2%80%93part-6.aspx) , but I cant get it to work, im just getting an Error loading MacroEngine script...

    @{

        var parentalLink = Model.GetPropertyValue("linkToParental", true); //Contenpicker

        var externalLink = Model.GetPropertyValue("linkToExternal", true); //Textfield

    }

     

    <div class="bottom-nav">

        <div class="bottom-left">

            <a class="btn parental" href="@parentalLink.Url"><span>For forældre</span></a>

        </div>

        <div class="bottom-right">

            <a class="btn play" href="@externalLink"><span>Fri leg</span></a>

        </div>

    </div>

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 17, 2014 @ 13:55
    Dennis Aaen
    0

    Hi Nicky,

    What abou if you do like this:

    @{

        var parentalLink = Model._linkToParental; //Contenpicker

        var externalLink = Model._linkToExternal; //Textfield

    }


    <div class="bottom-nav">

        <div class="bottom-left">

            <a class="btn parental" href="@parentalLink.Url"><span>For forældre</span></a>

        </div>

        <div class="bottom-right">

            <a class="btn play" href="@externalLink"><span>Fri leg</span></a>

        </div>

    </div>

    I hope this will work for you. The documentation can be found here: http://our.umbraco.org/documentation/Reference/Querying/DynamicNode/Properties

    /Dennis

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 17, 2014 @ 14:18
    Jeavon Leopold
    0

    Hi Nicky,

    Why you are using a Razor Macro (DynamicNode) with Umbraco v7 (I would like to know so we can see if we need to adjust documentation etc)

    In Umbraco v7, legacy Razor Macros (MacroScripts Folder) are for legacy support only. If you are using MVC templating then you can use Views and Partial Views, if you use MasterPage templates then you can use Macro Partial Views.

    Jeavon

  • Nicky Christensen 76 posts 166 karma points
    Jan 17, 2014 @ 14:53
    Nicky Christensen
    0

    I've changed it from a Razor Macro (Macroscripts folder) to a partial view macro, but still cant get it to work, both variables are empty - So it still doesnt get the properties recursive? 

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{

        var parentalLink = CurrentPage.GetPropertyValue("linkToParental", true); 

        var externalLink = CurrentPage.GetPropertyValue("linkToExternal", true); 

    }

    <div class="bottom-nav">

        <div class="bottom-left">

    <p>@parentalLink</p>

    <p>@externalLink</p>

            <a class="btn parental" href=""><span>For forældre</span></a>

        </div>

        <div class="bottom-right">

            <a class="btn play" href=""><span>Fri leg</span></a>

        </div>

    </div>

  • Paul Stoker 39 posts 72 karma points c-trib
    Jan 17, 2014 @ 15:02
    Paul Stoker
    0

     

    @Jeavon, the documentation says use CurrentPage in PartialViewMacros but with it being a dynamic type you get no intellisense in visual studio. Is traversing the content tree using Model.Content.Ancens... () just as acceptable?

    @Nicky, to make this work change 

    var parentalLink = CurrentPage.GetPropertyValue("linkToParental", true); 

    to:

    var parentalLink = Model.Content.GetPropertyValue("linkToParental", true); 
  • Nicky Christensen 76 posts 166 karma points
    Jan 17, 2014 @ 15:10
    Nicky Christensen
    0

    In the partial macroscript view, neither of these work:

    CurrentPage.GetPropertyValue("linkToExternal", true); 
    or
    Model.Content.GetPropertyValue("linkToExternal", true);  

    I tried both ways, and still returns nothing? 

  • Nicky Christensen 76 posts 166 karma points
    Jan 17, 2014 @ 15:38
    Nicky Christensen
    0

    I've also tried creating a Partial View, and then output it with: @Html.Partial("BottomNav");

    The code is almost the same, just inherits from another, but again, still returns nothing ? :( :

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{ 

        var externalLink = CurrentPage.GetProperyValue("linkToExternal");

    }

    <div class="bottom-nav">

        <div class="bottom-left">

    <p>@externalLink</p>

            <a class="btn parental" href=""><span>For forældre</span></a>

     

        </div>

        <div class="bottom-right">

            <a class="btn play" href=""><span>Fri leg</span></a>

        </div>

    </div>

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 17, 2014 @ 15:49
    Jeavon Leopold
    103

    The options are:

    CurrentPage._linkToExternal (the underscore makes it recursive)
    

    or

    Model.Content.GetPropertyValue("linkToExternal", true);  
    
  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 17, 2014 @ 16:05
    Dennis Aaen
    0

    So I also have the right solution just for when you are using Razor Macro (DynamicNode) scripts :-)

    /Dennis

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 17, 2014 @ 16:13
    Jeavon Leopold
    0

    @Dennis, yes you did indeed, just need to change Model to CurrentPage for MVC.

    It think there is a issue somewhere (maybe documentation, maybe elsewhere), in that new people using v7 who have MVC templating as default are still creating Legacy Razor Macros (DynamicNode) when they need to be using View/Partial Views/Macro Partial Views.

    Any thoughts?

  • Nicky Christensen 76 posts 166 karma points
    Jan 17, 2014 @ 16:19
    Nicky Christensen
    0

    Yeah, Dennis, if I were using DynamicNode, then you were also right :) 

    Another quick question - It looks like I cant use Model.NodeById() in the Partial View? When trying to render, the message is: Umbraco.Web.Models.RenderModel' does not contain a definition for 'NodeById' 

    var parentalLink = Model.Content.GetPropertyValue("linkToForaeldreForside", true);
    Line 6:      var externalLink = Model.Content.GetPropertyValue("linkToFriForMobberi", true); 
    Line 7: var parentalLinkNodeID = Model.NodeById(parentalLink);

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 17, 2014 @ 16:19
    Jeavon Leopold
    0

    @Paul, do you mean the documentation here which said "use Model.CurrentPage which exposes an instance of IPublishedContent or use CurrentPage", I've just fixed this to be "use Model.Content which exposes an instance of IPublishedContent or use CurrentPage" or somewhere else?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 17, 2014 @ 16:21
    Jeavon Leopold
    0

    Switch

    var parentalLinkNodeID = Model.NodeById(parentalLink); 
    

    for

    var parentalLinkNodeID = Umbraco.TypedContent(parentalLink);
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 17, 2014 @ 16:22
    Jeavon Leopold
    0

    or if using dynamics with CurrentPage, use:

    var parentalLinkNodeID = Umbraco.Content(parentalLink);
    
  • Nicky Christensen 76 posts 166 karma points
    Jan 17, 2014 @ 16:23
    Nicky Christensen
    0

    Great, thx alot, you've been a great help :) 

  • Paul Stoker 39 posts 72 karma points c-trib
    Jan 17, 2014 @ 16:24
    Paul Stoker
    0

    @Jeavon, yes that's right you got it ;-)

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 17, 2014 @ 16:42
    Jeavon Leopold
    0

    @Paul, great and thanks for spotting that. If you ever see any issues in the documentation, you can find the doc in the GitHub project, click edit, fix the issue and it will send us a pull request we can merge in.

Please Sign in or register to post replies

Write your reply to:

Draft