Copied to clipboard

Flag this post as spam?

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


  • Sam 63 posts 126 karma points
    Jul 03, 2014 @ 08:45
    Sam
    0

    Inline Razor script on Master Template won't get recursive.

    Hi All - 

    I have written the below script:

     

     @{

    if (@Model.HasValue("feesCharges")) {

    var pickerFC2 = @Model.NodeById(Model._feesCharges); 

    <div class="col text" onclick="window.open('@pickerFC2.url','_self');">Fees &amp; <span class="black">Charges</span></div>

    }

    else{

    <div class="col text">Fees &amp; <span class="black">Charges</span></div>

    }

    }

     

    on my Master Template.

    Basically it is a content picker - actually it works only on my homepage - but i want it to take the value recursively on interior pages.I have tried to put the _ before the property alias - but seems that i got it wrong - any help on this please.

     

    thanks

    //Sam

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 03, 2014 @ 09:16
    Jeavon Leopold
    100

    Hi Sam, you also need to make your HasValue recursive by adding true as a parameter

    if (Model.HasValue("feesCharges", true)) {
    
        var pickerFC2 = Model.NodeById(Model._feesCharges); 
    

    Additionally it's not a good idea to have @ in your code blocks

    Jeavon

  • Sam 63 posts 126 karma points
    Jul 03, 2014 @ 09:47
    Sam
    0

    Thanks a lot Jeavon - still learning all these razor tricks ; )

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 03, 2014 @ 10:01
    Jeavon Leopold
    0

    You're welcome. Do you know that the Razor Macros (DynamicNode) that you are using here is legacy now? If you are using Umbraco v6 or v7 it is recommended you use MVC views/partials directly or Partial View Macro if you really need a macro or are using WebForms instead.

  • Sam 63 posts 126 karma points
    Jul 03, 2014 @ 11:39
    Sam
    0

    Nice ... this seems like an interesting way to go..Will surely be digging further into that.

    Thanks again.

Please Sign in or register to post replies

Write your reply to:

Draft