Copied to clipboard

Flag this post as spam?

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


  • Carlos 338 posts 472 karma points
    May 18, 2012 @ 20:05
    Carlos
    0

    Issue with variables Razor erroring in page of templates

    I have a tree of nodes. In each of the templates that I have the same Razor Macro.  For some reason, variables are working in one of the templates but not others. I get 

    Error loading MacroEngine script (file: MinisiteHeaderLayoutOptionsRazor.cshtml)

    Here is my tree

    - sub master template
    ---sub template Home
    ---sub template Page
    ---sub template Single Col Page

    I put the macro in each of the sub templates. It works on the sub template Home but not on the "Page" or "Single Col Page".  I only have variable in the Razor script right now. I was going to add some code but ripped it out to see what was causing the issue. By process of elimination I found it was my variables of all things.  

    Any ideas on what would be causing simple variables to cause an error? thanks in advance

    My razor code is below:

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
    
        @*These vars are creating errors for some reason in Minisite page. Not sure why.*@
        var parentLink = @Model.NodeById(@Model.minisiteHomePage);
        var parentImgRunDates = Library.MediaById(@Model.minisiteRunDatesImage);
        var parentImg = Library.MediaById(@Model.minisiteLogo);
    
        @*
        if (@Model.HasValue("minisiteLogo") && @Model.HasValue("minisiteHomePage"))
        {
            <a href="@parentLink.Url">
                 <img src="@parentImg.Url" class="minisite-Logo" alt="@Model.minisiteLogoAltText"/>
            </a>
        }
        else if(@node1.HasValue("minisiteLogo") && @node1.HasValue("minisiteHomePage"))
        {
    
        }
        else{
        }*@
    
        @*
        if (@Model.HasValue("minisiteRunDatesImage"))
        {
            <img src="@parentImgRunDates.Url" class="minisite-ExhibitionRunDates" alt="@Model.minisiteRunDatesText"/>
        }*@
    
    }

     

  • Trevor Loader 199 posts 256 karma points
    May 20, 2012 @ 03:48
    Trevor Loader
    0

    You'll need to make sure that the properties minisiteHomePage, minisiteRunDatesImage and minisiteLogo are all properties available on the document type of the pages that are failing.

    If these properties are available on an ancestor, then try putting an "_" in front of each property so that Umbraco will walk back up the tree to try and find them.  Eg

      var parentLink =@Model.NodeById(@Model._minisiteHomePage);
      var parentImgRunDates =Library.MediaById(@Model._minisiteRunDatesImage);
      var parentImg =Library.MediaById(@Model._minisiteLogo);
Please Sign in or register to post replies

Write your reply to:

Draft