Benchpress template syntax

NodeBB Development
  • What is the syntax for OR condition?

    {{{ if A || B }}}

    {{{ if A OR B }}}

    Both are not working.

    Few more questions:

    What is the sytax for writing : if (condition) ... else if (condition) ... else ...

    Also, is its syntax case-sensitive?

    Is it documented? If yes, what is the link?

  • There is no OR, AND, EQUAL, etc. There isn't and ELSEIF, you have to do ELSE then IF. It's all documented here:

  • @pitaj
    I installed the benchpressjs package.
    In the tests directory, I created the htmls directory. Please help me finish / fix the file tpltohtml.js. The task of this file should be written to the htmls directory
    two categories.html and topic.html files that are converted from categories.tpl, categories.json, topic.tpl, topic.json

    'use strict';

    const fs = require('fs');
    const path = require('path');

    const { prepare, equalsIgnoreWhitespace } = require('./lib/utils');
    const Benchpress = require('../build/lib/benchpress');
    const mainData = require('./categories.json');

    const htmlDir = path.join(__dirname, 'htmls');

    function htmlWFile({ output, err }) {
    fs.writeFileSync(path.join(htmlDir, ${name}.html), `

      ${output == null ? `PRECOMPILE FAILED: ${err}` : output}


  • @rahmon what are you trying to do? What's the purpose of adding these files?

  • @pitaj

    I want to write only 1 file
    ---> tpltohtml.js, but I do not have enough knowledge. I'm programming in C ++.
    tpltohtml.js should generate in
    my htmls directory
    two files categories.html and topic.html that are converted from categories.tpl, categories.json, topic.tpl, topic.json
    I want to understand how to modify
    categories.tpl and topic.tpl. For this, I want to simplify everything as much as possible and discard all that is superfluous - leaving only bootstrap.js
    help me please finish
    file tpltohtml.js Then I'll be with him
    conduct experiments and this will help me understand how to modify the forum pages

  • @rahmon ok if you just want to experiment here's a little compile script that should work:

    const fs = require('fs');
    const path = require('path');
    const utils = require('util');
    const benchpress = require('benchpressjs');
    const writeFile = utils.promisify(fs.writeFile);
    const readFile = utils.promisify(fs.readFile);
    const files = process.argv.slice(2);
    const length = files.filter(x => x.endsWith('.json')).length;
    if (files.length / 2 !== length) {
      throw TypeError('Wrong arguments: provide equal numbers of templates and data');
    (async function () {
        const readFiles = await Promise.all( => readFile(path.join(__dirname, filename), 'utf8')));
        const readTemplates = readFiles.slice(0, length);
        const readDatas = readFiles.slice(length).map(text => JSON.parse(text));
        await Promise.all( function (template, i) {
            const rendered = await benchpress.compileRender(template, readDatas[i]);
            await writeFile(path.join(__dirname, files[i].replace(/tpl$/, 'html')), rendered);
        console.log('Templates rendered');
    1. Install Node.js v8 or v9
    2. Create a new completely separate directory
    3. Create compile.js with the above code
    4. Create *.tpl files and *.json files for each template you want to compile
    5. Run node compile [A template].tpl [B template].tpl ... [A data].json [B data].json ...
      (Make sure you send in the same number of templates and data)

    Then your templates should be rendered into *.html files (following the name of the input *.tpl file) in the same directory.

  • @pitaj
    Thank you so much.
    Write, please, what happens if you make a nested construction.
    There is a file index.tpl and header.tpl.
    Inside index.tpl I am writing a directive
    <!-- IMPORT header.tpl -->
    and this design does not work.
    Is there any system,
    which would print warnings if the directive can not be interpreted?

  • @rahmon IMPORT is actually a NodeBB directive, benchpress doesn't handle imports.

Suggested Topics

  • 0 Votes
    1 Posts


    How do I get the parent of the actual category in a Tamplate?

    Im just looking around and found this:

    <!-- IF breadcrumbs.length --> <ol class="breadcrumb"> <!-- BEGIN breadcrumbs --> <li<!-- IF @last --> component="breadcrumb/current"<!-- ENDIF @last --> itemscope="itemscope" itemtype="" <!-- IF @last -->class="active"<!-- ENDIF @last -->> <!-- IF !@last --><a href="{breadcrumbs.url}" itemprop="url"><!-- ENDIF !@last --> <span itemprop="title"> {breadcrumbs.text} <!-- IF @last --> <!-- IF !feeds:disableRSS --> <!-- IF rssFeedUrl --><a target="_blank" href="{rssFeedUrl}"><i class="fa fa-rss-square"></i></a><!-- ENDIF rssFeedUrl --><!-- ENDIF !feeds:disableRSS --> <!-- ENDIF @last --> </span> <!-- IF !@last --></a><!-- ENDIF !@last --> </li> <!-- END breadcrumbs --> </ol> <!-- ENDIF breadcrumbs.length -->

    How can I get the parent category-Name of the current (sub)category?
    Is there any reference I can use for such things in the future?

    What I like to do:

    Get the parent of the actual category use this value e.g. "foobar" to call the API of an external software and get JSON-Object depend on value "foobar" convert the data to display it between breadcrumbs / new topic in the nodeBB Forum

    Is it the right way to handle this with a template or am I completely wrong?
    I just installed nodeBB and I also do have no idea about node.js and all that stuff so sorry I am a noob. 🐵

    Kind regards, Pascal.

  • 0 Votes
    2 Posts

    Link the theme into node_modules with npm link and then use grunt to watch changes and rebuild automatically.

  • 0 Votes
    3 Posts

    added url property to all routes · NodeBB/NodeBB@8ea5752

    Node.js based forum software built for the modern web - added url property to all routes · NodeBB/NodeBB@8ea5752


    GitHub (

    It will be available in all routes, you can use it with {url}

  • 0 Votes
    3 Posts

    For example, I would like to replace username on topic, like shown on the screenshot:Image 1.png

  • 0 Votes
    13 Posts

    👍 sounds gud