Reputation: 177
I am trying to use a Razor template to produce a .aspx page as output. I'm not having luck looking in the documentation for how to do this. The Page and namespace declarations are breaking the template:
<%@ Page Language="C#" Title="@Page.Metadata.browser_title" %>
<%@ Import Namespace="System.Xml" %>
These are causing this error:
TemplateCompileException: CS1501: No overload for method 'Write' takes 0 arguments Line 27 Column 1: Write();
I assume this is because Razor templates using C# syntax makes the two conflict, since the declarations above use "@". Is there a way to get them to work together so a Razor template can produce an output with C# in the rendered product after the template is run? The example above also shows how the value for "Title" needs to be rendered out of the template.
Upvotes: 2
Views: 332
Reputation: 3547
If you like Razor, maybe you should check out DD4T (http://code.google.com/p/dynamic-delivery-4-tridion/). It allows you to build a web site using ASP.Net MVC with Razor views.
Upvotes: 2
Reputation: 4829
You could write a C# TBB to add the tags after all your Razormediator templates or even better if you could add after the Default Finish Actions(if you're using one).
Quick and dirty sample code...
Item OutputItem = package.GetByName(Package.OutputName);
string OutputText = OutputItem.GetAsString();
// Page tag declaration..
string pagePretags = @"<<TWO LINES OF DECLARATIONs..>>"
string FinalOutputText = pagePretags + OutputText ;
OutputItem.SetAsString(FinalOutputText);
Hope this helps..
Upvotes: 1
Reputation: 888223
The @
s in the <%
are invalid Razor syntax.
You need to escape them by writing <%@@
.
Upvotes: 6