Pug template conversion
johntom opened this issue · comments
John Tomaselli commented
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);
});
Kevin Van Lierde commented
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...