Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pug template conversion #1442

Open
johntom opened this issue Jun 15, 2023 · 2 comments
Open

Pug template conversion #1442

johntom opened this issue Jun 15, 2023 · 2 comments

Comments

@johntom
Copy link

johntom commented Jun 15, 2023

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);
  });

@johntom johntom changed the title oug conversion Pug template conversion Jun 15, 2023
@webketje
Copy link

webketje commented Nov 2, 2023

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...

@snth
Copy link

snth commented Mar 3, 2024

Hi,

I came here with a similar question (and as it turns out in order to convert the same htmx-tabular template 😂).

It looks like pypugjs can output Jinja2 templates so hopefully that would be compatible with nunjucks.

My plan is to try that when I've got a spare moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants