Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
huraken
@huraken
hey
Is it possible to use @Html or @Url with RazorEngine ?
Josh
@joshgo
@matthid Thank you for your response
mpbill
@mpbill
are there any demo applications available?
Matthias Dittrich
@matthid
@mpbill Only the example code/docs and real life open-source applications using RazorEngine, but I don't know any demo applications right now
mpbill
@mpbill
I dont understand ITemplateKeys. how can I construct a template key when each template key requires another 'context' template key?
BaseTemplateKey tk = new NameOnlyTemplateKey("page", ResolveType.Include, new NameOnlyTemplateKey(null, ResolveType.Include, new NameOnlyTemplateKey()));
etc
mpbill
@mpbill
So far the only way I can understand how to use a template is to read the *.cshtml file with a TextReader and pass that into Engine.Razor.RunCompile(). I feel there has to be a cleaner way of doing this, especially with all the classes I am seeing like TemplateManager, CachingProvider, TemplateKey etc... I just cant seem to find a good example of how to use one or all of these to automatically parse a template which i have created in my project. any help would be much appreciated!
Matthias Dittrich
@matthid
@mpbill Well you normally don't create TemplateKey instances yourself, those should be created by the TemplateManager. The manager and the IRazorEngineService provide APIs for this. More documentation can be found here: https://antaris.github.io/RazorEngine/TemplateManager.html. NOTE: context needs to be null for at least some templates. The idea is that the context gets set by RazorEngine when an inner template is resolved, but at the same time give you a possibility to pre-compile those templates.
Matthew Abbott
@Antaris
Wowzers, first time I've been here, didn't realise this was all so active! Thanks @matthid
Matthias Dittrich
@matthid
Nice to see you here @Antaris ;)
Paul Cox
@coxp
Hi guys, have we made any progress on CoreCLR support?
Matthias Dittrich
@matthid
I don't think somebody has looked into that jet. Maybe some code needs to be disabled because coreCLR doesn't support AppDomains....
Paul Cox
@coxp
Can we break things in v4? :)
Matthias Dittrich
@matthid
Yeah
Paul Cox
@coxp
Excellent. I've created a spike branch to see how feasible it is to isolate the Razor compilation into separate assemblies as I think this will help with CoreCLR support as well. I think we talked a long time ago about trying to modularize some of the functionality so maybe separating out the AppDomain support is a pre-requirement for CoreCLR support.
Paul Cox
@coxp
Are we using C#6 in RazorEngine going forward?
Matthias Dittrich
@matthid
I don't see any reason why we shouldn't, we can use C#6 to compile for .net40 as far as I know...
Paul Cox
@coxp
I'm not sure how well it works in VS 2013 but with VS 2015 Community edition and VS Code being free I'm not sure that is a valid reason not to use it.
Paul Cox
@coxp
My spike isn't going very well trying to brute-force the separation of the MS Razor bits from RazorEngine.Core :(. I think it needs a bit more thought as it is quite tightly coupled to MS Razor throughout the code base. Theoretically I think only the "template"->"source code" stage of the pipeline should depend on MS Razor? I also think I need to separate the configuration into configuration of our pipeline and configuration of the individual view engines (e.g. we could still support CodeInspectors in Razor2 & 3 then as it would be part of their configuration not the global configuration). As this change would force some configuration I'm not sure if it would be worth keeping the static Engine.Razor service.
Matthias Dittrich
@matthid
Yeah I tried as well and had a similar experience (see the split_api branch). Theoretically, yes you are correct. However there is a hidden dependency after we load the generated assembly and load the instance - as then we again need to have the type information for the 'TemplateBase' class which might depend on the MS Razor version... About the static class I'm not really sure if we need it (but a lot of users are used to use the library like this...). Maybe I shouldn't have shipped it with the new API, but I wanted to have an easy upgrade path.
jonleighmoneybox
@jonleighmoneybox
Hi. Has anyone had any joy creating templates with a layout in RazorEngine 3.5+?
Maxime Forest
@forestmaxime

Hi, I'm been having a problem with Engine.Razor.Compile method in a WCF app as of RazorEngine 3.7.5 (tried 3.7.7). Here's my stackoverflow question: http://stackoverflow.com/questions/35512454/razorengine-3-7-7-error-when-compiling-a-cached-template

Any ideas of a solution to fix that problem would be appreciated.

stavling
@stavling
Hello! Our project still uses 3.3.0 and gets KeyValueNotFoundException and no more information. There are no dictionaries in our model. Is this some internal error?
Frantisek Skorunka
@skorunka
Hi, I'm having an issue while "RazorEngine.RunCompile" view, where the "@model " is defined:
System.MissingMethodException: Method not found: 'Void Microsoft.AspNet.Razor.Parser.ParserContext.OnError(Microsoft.AspNet.Razor.SourceLocation, System.String)'.
at RazorEngine.Compilation.CSharp.CSharpCodeParser.ModelDirective()
It is "Microsoft.AspNet.Mvc": "6.0.0-rc1-final" + "RazorEngine": "4.2.7-beta1"
Mike Bateman
@MikeBateman
How do you add a For Loop in the razor view for VB?
Paul Lee
@WalkingMist
Hi, I would like to know is there anyway I can get the ViewModel type from TemplateKey?
Matthias Dittrich
@matthid
@WalkingMist No, because the default caching provider allows to compile the same template with different types: https://github.com/Antaris/RazorEngine/blob/master/src/source/RazorEngine.Core/Templating/InvalidatingCachingProvider.cs#L23
Paul Lee
@WalkingMist
@matthid, so there is no way to write methods to dynamically new an instance of the ViewModel from a given key or using the key to get to the template then get to the required ViewModel type?
Matthias Dittrich
@matthid
Depends on what you mean by no way. You can try to write your own caching provider with a simpler dictionary and ask it later for the type...
there is no way to know the type from a template at least. Consider for example layout templates, they can use whatever type their children is using
so I would say there is no sane way to do it. maybe some heuristic. the realquestion is what you want to achieve...
Paul Lee
@WalkingMist
@matthid, what I am trying to do is a message template engine, where I would like to have a single method to call and given the Template Key and a dictionary of parameters and be able to construct the final message. So I would like to have a method on the engine where I give it a template key and it will give me a new instance of the correct ViewModel so that I can populate it somehow
maybe it is too complex, so I have changed my mind and now the caller will construct the correct ViewModel type before passing that to the engine
Pauli Østerø
@burningice2866
Def. the way to go, no need to pass lossly typed dictionary when you can have a real class.
You can even take it a step further and decorate your ViewModel class with an attribute that holds the template key. Then the caller doesn't need to know about that, but just pass the view model and your engine can resolve the template key automatically.
Paul Lee
@WalkingMist
@burningice2866, that's a good idea!! Thank you.
Matthias Dittrich
@matthid
What Pauli says. Additionally you can already do it by creating a dynamic object from the dictionary (and use dynamic in your template)
Pauli Østerø
@burningice2866
I've created several message template engines like that mostly for emails, and that has been my approach.
Paul Lee
@WalkingMist
@burningice2866, lol, I am trying to make an email message template engine right now
@matthid I am not so sure about dynamic objects, never used it before, maybe it's time to look that up
Matthias Dittrich
@matthid
yeah use 'null' as your template type (= dynamic, see docs) and for example an expandoobject. Fill it up with your dictionary and it should work as expected...
Teck Loy Low
@Takaloy
Hi. I'm just trying out RazorEngine , going through the "getting started" guide, it doesn't seem like the documentation is up to date at all.
is there any chance to update it?
Teck Loy Low
@Takaloy
ah nevermind, figured it out. thanks!
Jelle Criel
@SnelleJelle
Hi, i'm trying out the engine and I'm having trouble using a class in my template
I can get the sample with the Anonymous Types running just fine
But I can't seem to use a List<Person> without having an exception blast in my face..
Can anyone help me out please? this is my simplified code