Skip to content

jntemplate is an fast and lightweight html templating engine for C# .NET.

License

Notifications You must be signed in to change notification settings

yxou/jntemplate

 
 

Repository files navigation

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

About

jntemplate is an fast and lightweight html templating engine for C# .NET.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 96.7%
  • CSS 1.5%
  • HTML 1.3%
  • Batchfile 0.2%
  • PowerShell 0.2%
  • Shell 0.1%