Passing in parameters for pug templates inside pug file
Asked Answered
E

1

5

Is it possible to pass in parameter for includeed pug files inside the parent pug file. For example if I have a child template example.pug:

p #{name}'s Pug source code!

And a parent parent.pug

h1
| Hello world
include example.pug

It would be nice to do something like

h1
| Hello world
include example.pug {name1}
include exmaple.pug {name2}

What is the way to do this?

Endorsee answered 17/4, 2018 at 17:53 Comment(0)
S
6

You can rewrite your include as a mixin, which accepts parameters.

mixins.pug

mixin person(name)
  p #{name}'s Pug source code!

parent.pug

include mixins.pug

h1 Hello world

+person('Kay')
+person('Jamal')

See the pug documentation for more info.

Shadowy answered 17/4, 2018 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.