Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
X

xtpl

> 编程语言
Open source

nodejs wrapper around xtemplate engine (easier for expressjs and koajs)

99 stars0 likes3 views
WebsiteGitHub

About

nodejs wrapper around xtemplate engine (easier for expressjs and koajs)

xtpl

nodejs wrapper around xtemplate engine (easier for expressjs and koajs)

docs

syntax

refer: https://github.com/xtemplate/xtemplate

api

methods

config or get xtpl global option:
javascript
Object config(option:Object)

option details:

    name
    type
    default
    description




  

      encoding
      String
      utf-8
      xtpl file encoding
  

  

      XTemplate
      Object
      require('xtemplate')
      xtemplate module value

if options is undefined, then this method will return global config.

render file
javascript
void renderFile(path:String, options:Object, callback:function)

parameter details:

    name
    type
    default
    description




  

      path
      String
      
      xtpl template file
  

  

      option
      Object
      
      
      data to be rendered. the following properties will be used for control.
      
          
          

              name
              type
              default
              description
          

          
          
            

                cache
                Boolean
                false
                whether cache xtpl by path
            

            

                setting['view encoding']
                String
                global encoding
                encoding for read xtpl files
            

          
      
      
  

  

      callback
      function
      
      callback
bash
npm install xtpl xtemplate --save
javascript
var xtpl = require('xtpl');
xtpl.renderFile('./x.xtpl',{
	x:1
},function(error,content){

});
express adaptor
javascript
xtpl.__express = xtpl.renderFile
clear cache

clear xtemplate cache cached by xtpl file path

javascript
void clearCache(path:String);

use for expressjs

javascript
var app = require('express')();
app.set('views','./views');
app.set('view engine', 'xtpl');
app.use(function(req, res){
    res.render('test',{data:1});
});

use for koa

javascript
var app = require('xtpl/lib/koa2')(new require('koa')(),{
    views:'./views'
});
app.use(async function(ctx){
    await ctx.render('test',{data:1});
});

Example

├── footer.xtpl
├── header.xtpl
├── index.xtpl
├── layout.xtpl
├── layout1.xtpl
└── sub
    └── header.xtpl

index.xtpl

{{extend ("./layout1")}}

{{#block ("head")}}


{{/block}}

{{#block ("body")}}

{{title}}

{{/block}}

layout1.xtpl

{{title}}
{{{block ("head")}}}


{{{include ("./header")}}}
{{{block ("body")}}}
{{{include ("./footer")}}}

render

res.render("index", {title: "xtpl engine!"})

output

xtpl engine!

header

sub header

xtpl engine!

footer

changelog

https://github.com/xtemplate/xtpl/milestones

License

xtpl is released under the MIT license.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言