DEV Community

Clive Da
Clive Da

Posted on

node pug dynamic html tables

here is an example of a pug STATIC html table

https://www.nodejsera.com/library/pug/pug-tables.html

here is an example of a node pug DYNAMIC html table

TABLE.PUG

table
  each r in tdata
    tr
      each c in r
        td=c

NODE.JS

const pug = require('pug');
  var html = await pug.renderFile('./templates/table.pug', { tablerows: [[1, 2], [3, 4]] })

INDEX.HTML

<table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table>

see

https://pugjs.org/language/iteration.html

you can even embed MARKDOWN in PUG

https://dev.to/patarapolw/pug-with-markdown-is-magic-yet-underrated-4dla

Top comments (1)

Collapse
 
keshavdutt profile image
keshavdutt • Edited

Here is a tutorial showing how to make table in pug. have a look