Search code examples
pug

write an array of objects directly on pug


I would like to know if I can write an object on pug, this code is working but I think I would be better if I can write the object directly.

mixin about(title, paragraphe)
  - var columns_content = []
  - columns_content.push({title:'Brand',paragraphe:'hola'})
  - columns_content.push({title:'Digital',paragraphe:'hola'})
  - columns_content.push({title:'Print',paragraphe:'hola'})

Solution

  • The symbol - allows you to use native javascript. So you can do this.

    - var columns_content = [
    -  {title:'Brand',paragraphe:'hola'},
    -  {title:'Digital',paragraphe:'hola'},
    -  {title: 'Print',paragraphe:'hola'}
    -  ]
    

    Or

    - var columns_content = [  {title:'Brand',paragraphe:'hola'},{title:'Digital',paragraphe:'hola'},  {title: 'Print',paragraphe:'hola'} ]