toondaey / nestjs-pdf

Nest js pdf generator
MIT License
83 stars 37 forks source link

Passing data #81

Open sulthanmamusa opened 3 years ago

sulthanmamusa commented 3 years ago

how to send data from service to template engine ( pug, handlebars etc.. )

smatioli commented 3 years ago

Hi, after a lot of guessing, I discovered that this way is possible to send data to handlebars and pug:

 this.pdfService.toStream('template', {
      locals: {
        title: 'My title',
      },
    });
riyasyash commented 3 years ago

@smatioli if you could , please post a sample template as well where this variables are replaced.

agusmathew commented 3 years ago
doctype html
html(lang="en")
  head
    title= title
    script(type='text/javascript').
  body
    h1 #{locals.title} - node template engine 
    #container.col
      if youAreUsingPug
        p You are amazing
      else
        p Get on it!
      p.
        Pug is a terse and simple templating language with a
        strong focus on performance and powerful features.

try these sample template to get the title passed as variable in your pdf

telou1 commented 2 years ago

Hello, if you have to make an iteration, how do you pass the array data? thanks!

agusmathew commented 2 years ago
ul
  - var count = 0;
  each item in items
    if count < 3
      li= item.name
    - count++;

try this please