TmodJS

raw JSON →
1.0.4 verified Fri May 01 auth: no javascript abandoned

TmodJS (formerly atc) is a front-end template precompilation tool that compiles HTML templates into JavaScript, enabling synchronous file loading in the browser. It supports artTemplate syntax, template organization by directory, and sub-template inclusion. The current stable version is 1.0.4, released in 2015. The project is abandoned; last update was 2017. Key differentiators: precompilation to eliminate runtime template parsing, optional module output in AMD, CMD, CommonJS, or default format, and file watching for incremental builds. Alternatives like Handlebars or EJS with precompilation offer more active maintenance.

error bash: tmod: command not found
cause TmodJS is not installed globally or not in PATH.
fix
Run npm install -g tmodjs and verify with npm list -g tmodjs.
error Error: Cannot find module 'tpl/build/news/list'
cause Template module path is wrong when using cmd/amd/commonjs type.
fix
Ensure the require path matches the output directory and omits file extension. E.g., require('./tpl/build/news/list').
error template is not defined
cause The compiled template.js file is not loaded or loaded out of order.
fix
Include the script before using template(): <script src="build/template.js"></script>.
error SyntaxError: Unexpected token '<'
cause Trying to directly load .html template files in Node.js without compilation.
fix
Use TmodJS to precompile templates to JS. Alternatively, use artTemplate's runtime loader but that is deprecated.
deprecated TmodJS is no longer maintained. Last release was 2015, last commit 2017. No future updates or security patches.
fix Migrate to actively maintained alternatives like Handlebars, EJS, or Nunjucks with precompilation.
gotcha CLI command is `tmod`, not `tmodjs`. Running `tmodjs` will result in 'command not found'.
fix Use `tmod` after installing `tmodjs` globally.
gotcha Template paths used with `template('path/to/template', data)` must not include the file extension.
fix Use `template('news/list', data)` instead of `template('news/list.html', data)`.
gotcha When using non-default module types (cmd, amd, commonjs), the output is separate files per template. The require path must not include the template suffix.
fix Use `require('./path/to/template')` without `.html` extension.
deprecated The grunt plugin `grunt-tmod` is not actively maintained and may not work with modern Node.js versions.
fix Use the CLI directly or switch to a modern build tool like Webpack or Vite with a template loader.
npm install tmodjs
yarn add tmodjs
pnpm add tmodjs

Installs TmodJS, creates a template file, compiles it to a single JS bundle, and uses the template function in an HTML page.

npm install -g tmodjs
mkdir -p tpl/news
cat > tpl/news/list.html <<EOF
<ul>
{{each list as item}}
    <li>{{item.title}}</li>
{{/each}}
</ul>
EOF
tmod ./tpl --output ./build
cat > index.html <<EOF
<!DOCTYPE html>
<html><body>
<div id="list"></div>
<script src="build/template.js"></script>
<script>
var list = [{title:'Item 1'},{title:'Item 2'}];
var html = template('news/list', {list: list});
document.getElementById('list').innerHTML = html;
</script>
</body></html>
EOF