Copied to clipboard

Flag this post as spam?

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


  • hetaurhet 245 posts 267 karma points
    Nov 12, 2011 @ 12:01
    hetaurhet
    0

    error rendering razor

    I have following razor script. script file is saving successfully but error for rendering on page. Below is the code where RelatedBooks is doc type and prayerHeading is field of that doctype. So what's the mistake?

    @*
    All CSS ID and Classes that have been applied in this script have been referenced in the GnanVidhi Page Template.
    *@
    @using umbraco.BusinessLogic;
    @using dadabhagwan.org;
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
                         
    var node = @Model.Node;
     
     if(@node.NodeTypeAlias == "RelatedBooks")
      {
       
         if(@node.prayerHeading == "Try yourself to experience guaranteed happiness - ")
         {
           <img alt="" class="left" src="/images/expand/try.png" align="absmiddle" />
         }
         else if(@node.prayerHeading == "Keys to remain in Brahmacharya - ")
         {
           <img alt="" class="left" src="/images/expand/key.png" align="absmiddle" />
         }
         else if(@node.prayerHeading == "Result of attaining Gnan Vidhi... - ")
         {
           <img alt="" class="left" src="/images/expand/solution.png" align="absmiddle" />
         }
         else
         {
       
           <img alt="" class="left" src="/images/expand/try.png" align="absmiddle" />
        
         }
         
      }
    }

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Nov 13, 2011 @ 09:39
    Darren Ferguson
    0

    What is the error when rendering the page?

  • hetaurhet 245 posts 267 karma points
    Nov 14, 2011 @ 05:59
    hetaurhet
    0

    just that razor cannot be rendered.. .thats it..

    I think i have problem with line .....  var node = @Model.Node; ... how can I access current node?

  • Jonas Eriksson 930 posts 1825 karma points
    Nov 14, 2011 @ 07:32
    Jonas Eriksson
    0

    Hi,

    actually you have it already with Model. So you should be able to use for example Model.PrayerHeading

  • UmbracoNewb 31 posts 53 karma points
    Nov 14, 2011 @ 09:24
    UmbracoNewb
    0

    As Jonas says, you already have the node with Model. So there is no need for var node @Model.Node (and by the way, there is no need for @ either when you are already in a code block) just use:

     if(Model.NodeTypeAlias == "RelatedBooks")

    To ease your code you could use a switch instead of the if/else combinations:

    switch((String)Model.prayerHeading){
      case "Try yourself to experience guaranteed happiness - ":
        <img alt="" class="left" src="/images/expand/try.png" align="absmiddle" />
        break;
      case "Keys to remain in Brahmacharya - ":
        <img alt="" class="left" src="/images/expand/key.png" align="absmiddle" />
        break;
      default:
    <img alt="" class="left" src="/images/expand/try.png" align="absmiddle" />
        break;
      }
    } 

  • hetaurhet 245 posts 267 karma points
    Nov 15, 2011 @ 05:42
    hetaurhet
    0

    thank you for guiding.. I am new to razor scripting...

  • UmbracoNewb 31 posts 53 karma points
    Nov 15, 2011 @ 08:18
    UmbracoNewb
    0

    I am new to Razor too :)

Please Sign in or register to post replies

Write your reply to:

Draft