Benchpress template syntax

  • 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?

  • Global Moderator

    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}


  • Global Moderator

    @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

  • Global Moderator

    @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?

  • Global Moderator

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


| |