mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)

Home Page:https://mozilla.github.io/nunjucks/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pug template conversion

johntom opened this issue · comments

I'm trying to convert the following respo (https://github.com/rajasegar/htmx-tabular) from pug templates to nunjucks. I've successfull used numjucks with fastify but have problem converting the following refresh of template.

  app.post('/search', (req,res) => {
    const { sortBy, direction, start } = req.query;
    const { query } = req.body;
    console.log(query);
    const data = query ? restaurants.filter(r => r.name.includes(query)) : restaurants;
  
    const reverse = direction === 'asc' ? 'desc' : 'asc';
    const sortedData = direction === 'asc'
      ? R.sortWith([R.ascend(R.prop(sortBy))], data)
      : R.sortWith([R.descend(R.prop(sortBy))], data);
  
    const totalPages = sortedData.length / 10;
    const _restaurants = sortedData.slice(start, Number(start) + 10);
   // tring to convert to nunjucks
    const template = pug.compileFile('views/_table.pug');
    const markup = template({ restaurants: _restaurants, sortBy, reverse, direction, start, totalPages, totalResults: sortedData.length });
    res.send(markup);
  });

Please describe the problem in more detail. Does it result in errors? What is missing after the rendering? What have you tried? Are you not able to call methods, etc...