45 Star 195 Fork 41

翅膀的初衷 / jntemplate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

JNTemplate

Build status GitHub stars GitHub stars GitHub license GitHub issues

English | 中文

JNTemplate 是什么

极念模板引擎(JNTemplate)是一款完全国产的基于C#语言开发的跨平台的文本解析引擎(模板引擎),它能生成任何基于文本的内容,包括且不限于html,xml,css等,让前端展示与后端代码逻辑分离。同时,它也提供了一个在WebForm与Razor之外的选择!

JNTemplate所有代码全部开源,且具有最小的依赖关系,能轻松实现迁移与跨平台。同时,在满足我们开源协议的前提下,大家可以自由使用,分发,和用于商业目的(具体见License.txt)。

从2.0版本开始,引擎全面升级为编译型模板引擎,在性能上得到了更大的提升。

特点:

  • 更快速:高效的IL模板预编译机制,让运行速度接近原生体验。
  • 更简单:语法简单易学,有一定前后端基础,最快可以10分钟上手
  • 更方便:能自由配置各项参数,扩展自己的标签。
  • 更自由:支持商用无须任何费用,所有代码完全开源。

安装

使用 NuGet安装或者更新:

PM> Install-Package JinianNet.JNTemplate

or

> dotnet add package JinianNet.JNTemplate

快速开始

基本用法

使用预设的数据渲染模板

c# 代码

var template = Engine.LoadTemplate(@"c:\wwwroot\view\index.html");
template.Set("name", "jntemplate");
var result = template.Render(); 

模板文件index.html

<!DOCTYPE html>
<html>
<body>
  <h1>Hello, ${name}</h1>
</body>
</html>

输出结果:

<!DOCTYPE html>
<html>
<body>
  <h1>Hello, jntemplate</h1>
</body>
</html>

迭代列表

使用foreach快速迭代一个列表

c# 代码

var template = Engine.LoadTemplate(@"c:\wwwroot\view\view.html"); ;
template.Set("list", new string[] { "github","jntemplate" });
var result = template.Render(); 

模板文件:view.html

<ul>
${foreach(name in list)}
	<li>${name}</li>
${end}
</ul>

输出结果:

<ul>
	<li>github</li>
	<li>jntemplate</li>
</ul>

更多完整用法请查看API文档(地址见下面的链接)

配置

你可以使用IOptions对象来对 JNTemplate进行配置:

Engine.Configure((options)=>{
    // .. 配置你的具体参数
});

链接

授权

MIT 详细请查看 License.txt(1.4以下版本为apache 2.0)

联系方式:

The MIT License Copyright (c) jiniannet (http://www.jiniannet.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

C#开发的高速.NET模板引擎 展开 收起
取消

发行版 (17)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/jiniannet/jntemplate.git
git@gitee.com:jiniannet/jntemplate.git
jiniannet
jntemplate
jntemplate
master

搜索帮助