1.1.1 • Published 4 years ago
smarty-server v1.1.1
node-smarty-server
Render smarty template in local for quick development.
install
npm i [-g] smarty-server
usage
config file
make a config file like this:
const fs = require('fs'); const path = require('path'); module.exports = { routes: { '/': { templatePath: '/path/to/index.tpl' }, '/page': { templatePath: '/path/to/another/page.tpl' } }, // smarty will find template based on this path templateRootPath: path.resolve(__dirname, '../output/template'), // will start a static file server on this path staticRootPath: path.resolve(__dirname, '../output'), smartyConfig: { delimiters: { left: '{%', right: '%}' } }, // will load smarty plugins in these paths, can be a string or string[] pluginPaths: path.resolve(__dirname, '../tool/plugins'), // will use this function's return as data to render template mockData(url) { return fs.readFileSync(path.resolve(__dirname, './mock.json'), {encoding: 'utf8'}); } };
run
smarty-server start -c path/to/config.js