Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Matthias Dittrich
@matthid
Sadly RazorEngine only shines for Html and XML (and xml can already be hard)...
Anders
@brigs
I agree it's not an ideal fit, but it still feels vastly simpler than T4 in some cases
Matthias Dittrich
@matthid
Ideally we would have Antaris/RazorEngine#223, which would improve this scenario a lot. But I don't think this will be implemented anytime soon :(
Anders
@brigs
Looks interesting! Have you got any pointers to custom parser implementations ?
Ie. have any other projects done similar things with razor
Matthias Dittrich
@matthid
Yes I have started to implement a custom one for F# but never manged to finish it... On this occasion I always looked into the html parser and actually implementing the <text></text> only parser should just be a matter of removing everything from the html parser, which is here: https://github.com/aspnet/Razor/blob/dev/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.cs
But I warn you it is a bit hard to get into this double parser thing initially
Anders
@brigs
I can imagine :)
Anders
@brigs
Just a thought about the "quick start" documentation, I get that you want it in the simplest form possible, but I think an actual sample of a a simle cshtml would be very nice to have there. What do you think?
Matthias Dittrich
@matthid
Yeah the idea was that people using RazorEngine are already familiar with Razor itself... That could be wrong though.
Anders
@brigs
I have used razor previously but a simple @model directive just didn't work for me
I googled and found an example (perhaps outdated)
let me show a gist
but then again, I haven't used Razor for years so I might be horribly mistaken :-D
Matthias Dittrich
@matthid
K2Template must be in the hosting application, but the rest should work what's the exact problem?
Anders
@brigs
Sorry I was a bit unprecise, what I pasted works just fine, but I was, perhaps very naively, expecting to just declare a model like this: @model MyNameSpace.MyModel
Matthias Dittrich
@matthid
instead of @inherits? Yes that should work as well, but I personally always use @inherits because it works better with the Visual Studio designer...
Anders
@brigs
yeah instead of, I always just used @model before
but as I said, I haven't really messed with razor since mvc3 so I'm really outdated
Anders
@brigs
It seems @inherits is clearly preferred when outside of a web context anyway
Matthias Dittrich
@matthid
seriouz
@seriouz
Anyone here? :)
Matthias Dittrich
@matthid
yes :)
seriouz
@seriouz
hi matthid can you help me with a custom TemplateManager?
Matthias Dittrich
@matthid
What's the problem?
Jeffrey Zhao
@JeffreyZhao
Hi forks

I'm using RazorEngine v2 but run into issue with @Include.

string helloWorldTemplate = "Hello @Model";
Razor.CompileWithAnonymous(helloWorldTemplate, "helloWorld");

string fullTemplate = "@Include(\"helloWorld\", @Model.Name)! Welcome to Razor!";
string result = Razor.Parse(fullTemplate, new { Name = "World" });

I expected “Hello World” but get "Hello RazorEngine.Compilation.RazorDynamicObject".

Anyone can help?

Matthias Dittrich
@matthid
That looks like a bug, I'll look into it.
I get the expected Hello World. Can you update to the latest version?
Jeffrey Zhao
@JeffreyZhao
some dll we use is linked to v2. I'll try to upgrade to v3 with binding directions. Is v3 fully compatible with v2?
Matthias Dittrich
@matthid
No not really, it's possible that you need to recompile that dll. However you should give it a shot as the legacy API is still there and working.
Jeffrey Zhao
@JeffreyZhao
OK, thx
BTW, the dll is RazorEngine.dll, Version=2.1.4039.23635. That's from a legacy project so I don't know when and where it get the dll from.
Matthias Dittrich
@matthid
And if you encounter an issue write it here as we may be able to fix it.
Jeffrey Zhao
@JeffreyZhao
cool, thx
Matthias Dittrich
@matthid
I don't know the version you mentioned, as I started maintaining the project on version 3.4 :)
So maybe they used the same version as Razor.dll back then
Jeffrey Zhao
@JeffreyZhao
yes it's pretty old, at least 3 years I believe. I'm trying to upgrade to version 3.x. Hope nothing breaks. :)
Matthias Dittrich
@matthid
So this is still net40, right?
Jeffrey Zhao
@JeffreyZhao
yes, .net 4.0.
Matthias Dittrich
@matthid
Good luck
Matthias Dittrich
@matthid
Microsoft stopped supporting net40 and Razor3 is only build for net45. But we actually still support net40 by referencing Razor2 on the net40 build. So make sure you reference the correct .dll (nuget should take care of this). Just note that there are some bugs on the Razor parser which will never get fixed (there are some unit tests within RazorEngines test suite)... And the two builds are not compatible with the other Razor version. So for example if you are a library and reference RazorEngines net40 build and your caller redirects Razor2 to Razor3 everything will fail miserably (The same is true the other way around, which shouldn't happen in practice) ...
Jeffrey Zhao
@JeffreyZhao
well, just found the lastest RazorEngine.dll has the different publicKeyToken from the legacy one we're using. It looks that I need to recompile RazorEngine by ourselves.
Yes, I've tried RazorEngine 3.6.5.0 in a .net 4.0 console, and it works fine. It's using System.Web.Razor.dll instead of Microsoft.AspNet.Razor.dll.
Matthias Dittrich
@matthid
Microsoft.AspNet.Razor.dll is Razor4 if I'm not mistaken
which I guess will bring additional headache :(
Jeffrey Zhao
@JeffreyZhao
I'm not very clear about that. I'm playing RazorEngine 3.6.5.0 in an .net 4.0 console project. After compiling it has only System.Web.Razor.dll in bin folder so I think Microsoft.AspNet.Razor is not required.
Anyway, let me try to download the source code of RazorEngine v2 and v3, then compiling v3 with v2's key.
Matthias Dittrich
@matthid
Yeah those two are the same thing https://www.nuget.org/packages/Microsoft.AspNet.Razor/ pre 4.0 versions call their dll System.Web.Razor.dll and >4.0 versions Microsoft.AspNet.Razor.dll for whatever reason