百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
X

xtpl

> 编程语言
开源

围绕 xtemplate 引擎的 nodejs 包 (对于 expressjs 和 koajs 更方便)

99 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

围绕 xtemplate 引擎的 nodejs 包 (对于 expressjs 和 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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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