Compilation issue

Topics: Customizing Orchard, General
Dec 10, 2012 at 10:39 AM
Edited Dec 10, 2012 at 9:35 PM

Whilst creating a new theme I came across a strange issue with a code block at the top of my layout.cshtml view. I had originally written the code like this:

@{ 
    SetMeta("X-UA-Compatible", "IE=edge,chrome=1"); 
    SetMeta("viewport", "width=device-width, initial-scale=1, maximum-scale=1"); 

    Style.Include("skeleton.css");
    Style.Include("base.css");
    Style.Include("layout.css");
    Style.Include("orchard.css");
    Style.Include("http://fonts.googleapis.com/css?family=Anton"); 
    Style.Include("http://fonts.googleapis.com/css?family=Patua+One"); 

    var siteName = @WorkContext.CurrentSite.SiteName; 
    var homeUrl = Href("~/); 
    var contentClass = "three-thirds column"; 

    if (Model.Aside != null) 
    { 
        contentClass = "two-thirds column"; 
    }
} 

When viewing the site it would throw an exception complaining about a missing brace. Viewing the compilation source revealed that one of the braces in my code had been removed on line 77:

 

Line 55:           public override void Execute() { 
Line 56:                
Line 57:               #line 3 "C:\inetpub\wwwroot\Themes\Teched\Views\Layout.cshtml" 
Line 58:      
Line 59:       SetMeta("X-UA-Compatible", "IE=edge,chrome=1"); 
Line 60:       SetMeta("viewport", "width=device-width, initial-scale=1, maximum-scale=1"); 
Line 61:    
Line 62:       Style.Include("skeleton.css"); 
Line 63:       Style.Include("base.css"); 
Line 64:       Style.Include("layout.css"); 
Line 65:   Style.Include("orchard.css"); 
Line 66:       Style.Include("http://fonts.googleapis.com/css?family=Anton"); 
Line 67:       Style.Include("http://fonts.googleapis.com/css?family=Patua+One"); 
Line 68:    
Line 69:   var siteName = @WorkContext.CurrentSite.SiteName; 
Line 70:       var homeUrl = Href("~/"); 
Line 71:    
Line 72:       var contentClass = "three-thirds column"; 
Line 73:    
Line 74:       if (Model.Aside != null) 
Line 75:       { 
Line 76:           contentClass = "two-thirds column"; 
Line 77:        
Line 78:                
Line 79:               #line default 
Line 80:               #line hidden 
Line 81:   WriteLiteral("\r\n}\r\n\r\n

 

However, if I change the order of my code so that the check for any aside content is not the last thing to be executed it works fine:

@{    
    SetMeta("X-UA-Compatible", "IE=edge,chrome=1");
    SetMeta("viewport", "width=device-width, initial-scale=1, maximum-scale=1");
    
    Style.Include("skeleton.css");
    Style.Include("base.css");
    Style.Include("layout.css");
    Style.Include("orchard.css");
    Style.Include("http://fonts.googleapis.com/css?family=Anton");
    Style.Include("http://fonts.googleapis.com/css?family=Patua+One");

    var contentClass = "three-thirds column";

    if (Model.Aside != null)
    {
        contentClass = "two-thirds column";
    }
    
    var siteName = @WorkContext.CurrentSite.SiteName;
    var homeUrl = Href("~/");
}

Coordinator
Dec 14, 2012 at 3:06 AM

I think the @ in front of WorkContext is the problem here. It shouldn't be there.

Dec 17, 2012 at 9:20 AM
bertrandleroy wrote:

I think the @ in front of WorkContext is the problem here. It shouldn't be there.

Spot on, cheers Bertrand! Removed the @ and everything works as expected, I must pay more attention next time!