Created
November 29, 2011 00:34
-
-
Save drch-/1402784 to your computer and use it in GitHub Desktop.
RazorEngine Model/Layout Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using RazorEngine.Configuration; | |
using RazorEngine.Templating; | |
namespace RazorTest | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
var parent = @"@Model.Name @RenderBody()"; | |
var resolver = new SimpleResolver(new Dictionary<string, string> {{"Parent", parent}}); | |
var config = new TemplateServiceConfiguration() {Resolver = resolver}; | |
using (var service = new TemplateService(config)) | |
{ | |
var child = @"@{_Layout = ""Parent"";} @Model.Name"; | |
var model = new {Name = "Hello World"}; | |
var result = service.Parse(child, model); | |
Console.WriteLine(result); | |
} | |
} | |
} | |
internal class SimpleResolver : ITemplateResolver | |
{ | |
private readonly IDictionary<string, string> _templates; | |
public SimpleResolver(IDictionary<string, string> templates) | |
{ | |
_templates = templates; | |
} | |
public string Resolve(string name) | |
{ | |
return _templates[name]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment