{"id":25729,"library":"hogan.js","title":"Hogan.js","description":"Hogan.js is a Mustache templating compiler developed by Twitter, currently at version 3.0.2. It compiles Mustache templates into reusable HoganTemplate objects with a fast, three-phase process (scanning, parsing, code generation). It supports custom delimiters, template inheritance, pre-compilation, and a parser API for server-side processing. Key differentiators: standalone templates (render without the compiler), lambda features (optional), and compatibility with other Mustache implementations. Release cadence is irregular; latest release is from 2014.","status":"maintenance","version":"3.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/twitter/hogan.js","tags":["javascript","mustache","template"],"install":[{"cmd":"npm install hogan.js","lang":"bash","label":"npm"},{"cmd":"yarn add hogan.js","lang":"bash","label":"yarn"},{"cmd":"pnpm add hogan.js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export; CommonJS require also works, but ES module import is preferred in modern codebases.","wrong":"const hogan = require('hogan.js');","symbol":"Hogan","correct":"import Hogan from 'hogan.js'"},{"note":"Hogan is not a constructor; compile is a static method.","wrong":"const template = new Hogan('Hello {{name}}!')","symbol":"Hogan.compile()","correct":"const template = Hogan.compile('Hello {{name}}!')"},{"note":"Named export for the template class; can be used if you have pre-compiled templates.","wrong":"const HoganTemplate = require('hogan.js').HoganTemplate","symbol":"HoganTemplate","correct":"import { HoganTemplate } from 'hogan.js'"},{"note":"Scan returns an array of tokens, parse returns an AST. Useful for server-side preprocessing.","wrong":"","symbol":"Hogan.scan() / Hogan.parse()","correct":"const tokens = Hogan.scan('{{foo}}'); const tree = Hogan.parse(tokens);"}],"quickstart":{"code":"// Quickstart: compile and render a template\nimport Hogan from 'hogan.js';\n\nconst data = {\n  name: 'World'\n};\n\n// Compile template string\nconst template = Hogan.compile('Hello {{name}}!');\n\n// Render with data\nconst output = template.render(data);\n\nconsole.log(output); // 'Hello World!'\n\n// Pre-compile and render without compiler\nconst precompiled = Hogan.compile('Hello {{name}}!', { asString: true });\n// Send precompiled string to client, then:\n// const HoganTemplate = ... // need Hogan runtime\n// const template = new HoganTemplate(precompiled);\n// template.render(data);","lang":"javascript","description":"Demonstrates basic template compilation and rendering using Hogan.js."},"warnings":[{"fix":"Ensure the compiler and source are available at render time if using lambdas.","message":"Lambda features require the compiler and original template source; pre-compiled templates without the compiler cannot use lambdas.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Consider migrating to maintained alternatives like Handlebars or mustache.js.","message":"The project is no longer actively maintained; last release was in 2014. Security updates are not guaranteed.","severity":"deprecated","affected_versions":"all"},{"fix":"Use `new HoganTemplate(compiledString)` after receiving the string.","message":"Hogan.compile() with { asString: true } returns a string, not a template object; you must later instantiate a HoganTemplate.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Check delimiter format; use exactly two tokens separated by a space.","message":"Custom delimiters must be specified as a string with two delimiters separated by space, e.g., '<% %>'. Incorrect format will be silently ignored.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Replace `new Hogan(template)` with `Hogan.compile(template)`.","cause":"Using `new Hogan(...)` instead of `Hogan.compile(...)`. Hogan is an object with static methods, not a constructor.","error":"Hogan is not a constructor"},{"fix":"Run `npm install hogan.js` and ensure import/require path is correct (e.g., require('hogan.js')).","cause":"Missing npm install or incorrect import path.","error":"Cannot find module 'hogan.js'"},{"fix":"Import HoganTemplate from 'hogan.js' or access it as Hogan.HoganTemplate.","cause":"Trying to use HoganTemplate class without importing it; it is a named export.","error":"HoganTemplate is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}