javascriptnode.jsincludepugpugjs

jade/pug Is it possible to use variables on include statement?


I'm developing nodejs application and I have issue with include statement. It works when I use it like this:

include ../mixins/root.pug

...but is it possible to use variables on include?

None of these work:

include #{process.env.MIXINS_PATH}/root.pug
include !{process.env.MIXINS_PATH}/root.pug
include `${process.env.MIXINS_PATH}/root.pug`

Result is this:

Error: ENOENT: no such file or directory

Solution

  • Dynamic includes are not supported:

    We don't support "Dynamic Include". There are lots of issues people have opened about this. It's really complex to implement and not actually nearly as useful as people think it would be.

    https://github.com/pugjs/pug/issues/2622#issuecomment-270157667