45 Star 198 Fork 41

翅膀的初衷/jntemplate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 2.46 KB
一键复制 编辑 原始数据 按行查看 历史
翅膀的初衷 提交于 2022-09-13 22:09 . 增加.NET framework 2.0支持

JNTemplate

Build status GitHub stars GitHub stars GitHub license GitHub issues

English | 中文

What is JNTemplate?

JNTemplate is fast, lightweight, extensible .net template engine for generating html, xml, sql, or any other formatted text output.

Special placeholders in the template allow writing code similar to c# syntax. Then the template is passed data to render the final document.

Installation

Install and update using NuGet:

PM> Install-Package JinianNet.JNTemplate

or

> dotnet add package JinianNet.JNTemplate

Quickstart

Basics

Rendering a basic html template with a predefined data model.

c# code

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>

output:

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

Iteration

Iteration is achieved by using the foreach binding on the element you wish to iterate.

c# code

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>

output:

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

Configuration

You can configure JNTemplate with the IOptions class.

Engine.Configure((options)=>{
// .. configure your instance
});

Links

Licenses

MIT

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/jiniannet/jntemplate.git
git@gitee.com:jiniannet/jntemplate.git
jiniannet
jntemplate
jntemplate
master

搜索帮助

Cb406eda 1850385 E526c682 1850385