volkovku / RazorTemplates

Open source templating engine based on Microsoft's Razor parsing engine. Thread safe. Allows run Razor templates outside ASP.Net MVC Projects.
Microsoft Public License
99 stars 31 forks source link

Question: Is THIS the lib to use? #6

Open lorddev opened 11 years ago

lorddev commented 11 years ago

I found this on StackOverflow, and I had found RazorEngine as well. However, it seems RazorEngine hasn't been updated in about 2 years, which makes it older than MVC 4, which doesn't seem like a good time. This library, however, has been updated in recent months. So is this the better one to use?

volkovku commented 11 years ago

Hi, Aaron! RazorTemplates like a RazorEngine is a simple wrapper to Razor View Engine 2.0. The common difference is in API. In my opinion RazorTemplates API is more robust then RazorEngine API. You can manage compiled templates as you want. See examples and you can feel difference. But RazorTemplates has a weaknesses. It's very simple wrapper, and does not in the box features like HtmlHelper. I use it in my projects for localize strings, for email and notifications templating, and it's work fine. If you want but not found some features in RazorTemplates you can write me and a I can implement it.

Eibwen commented 9 years ago

Hello @volkovku, I'm having trouble getting RazorEngine to work with external assemblies (for example I was using JsonConvert and StructureMap). Would RazorTemplates be able to reference assemblies?

This does seem to work (in both RazorTemplates and RazorEngine)... but is there any simpler way?

public static void TemplateWithThirdPartyNamespaces()
{
    JsonConvert.SerializeObject(new object { }); //Fake usage or external reference in the code just before Parsing the template
    var template = Template
        .WithBaseType<TemplateBase>()
        .AddNamespace("Newtonsoft.Json")
        .Compile(@"In json this is @JsonConvert.SerializeObject(Model)");

    Console.WriteLine(template.Render(new { Apples = 6, Oranges = 5 }));
}

Or anybody know how to do this with any similar project? Thought I would throw this question out there because it doesn't seem to be addressed for any project similar to yours or razor engine.

JasonFoglia commented 9 years ago

@Eibwen check out my question here:

https://github.com/volkovku/RazorTemplates/issues/14