在 .NET/C# 中渲染 Handlebar 模板服务器端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15814781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Render Handlebar templates server side in .NET/C#
提问by Paul Grimshaw
Is there an existing library to render handlebar templates in .NET?
是否有现有的库可以在 .NET 中呈现车把模板?
I would like to use this as a templating engine for users to create HTML email templates
我想将其用作模板引擎,供用户创建 HTML 电子邮件模板
I've spent a few hours looking, but can't seem to find anything. A wrapped up javascript rendering model would be ok, but a native library better.
我花了几个小时寻找,但似乎找不到任何东西。包装好的 javascript 渲染模型可以,但本机库更好。
Otherwise, is there a similar templating engine more suited to the .NET environment?
否则,是否有更适合 .NET 环境的类似模板引擎?
采纳答案by Paul Grimshaw
Typical, shortly after posting I think I found the solution:
典型的,发布后不久我想我找到了解决方案:
https://github.com/jehugaleahsa/mustache-sharp#readme
https://github.com/jehugaleahsa/mustache-sharp#readme
The 'Mustache' in the name confused me, but in fact this library is based on the handlebars syntax.
名称中的“Mustache”让我感到困惑,但实际上这个库是基于把手语法的。
I have since started my own Fork of this library, to enable "Greater Than/Less Than/Equal To" tags:
从那以后,我开始了我自己的这个库的 Fork,以启用“大于/小于/等于”标签:
回答by DaveRead
If you want to use Handlebar server side then have a look at node.js and these two questions:
如果你想使用 Handlebar 服务器端,那么看看 node.js 和这两个问题:
Node.js with Handlebars.js on server and client
在服务器和客户端上使用 Handlebars.js 的 Node.js
回答by Simon Boudrias
Handlebars have really been made for user inside the browsers. I don't think it's a good idea to use it on the server (Even node.js don't have a server side Handlebars compiler)
把手确实是为浏览器内的用户制作的。我认为在服务器上使用它不是一个好主意(即使 node.js 没有服务器端 Handlebars 编译器)
Although, Handlebars base syntax is derived from the Mustache templating engine. And, Mustache have direct support for .NET!
虽然 Handlebars 基本语法源自Mustache 模板引擎。而且,Mustache 直接支持 .NET!
回答by Nathan
Another option is a wrapper of the actual handlebars.js library in C# via the V8 bindings. https://github.com/pressf12/handlebars.cs
另一种选择是通过 V8 绑定在 C# 中封装实际的 handlebars.js 库。 https://github.com/pressf12/handlebars.cs
回答by Adam Bell
It seems like you would prefer to use handlebar views server side, but if you want to compile them server side, in C#, and render them client side then I have found 2 options:
似乎您更喜欢使用车把视图服务器端,但如果您想在服务器端编译它们,在 C# 中,并在客户端呈现它们,那么我找到了 2 个选项:
回答by Rex M
Since this question was answered, a full-blown, native .NET library for Handlebars became available (disclosure: I am the primary author).
自从这个问题得到解答后,一个完整的、用于 Handlebars 的原生 .NET 库就可用了(披露:我是主要作者)。
Handlebars.Net on GitHuband on NuGet
It compiles Handlebars templates to IL, and has excellent feature coverage.
它将 Handlebars 模板编译为 IL,并具有出色的功能覆盖。