B
B
BestJS2022-04-12 16:28:25
Pug
BestJS, 2022-04-12 16:28:25

How to insert text with a variable in Pug?

I looked all over but couldn't find an answer.
Let me explain with an example:

res.render.call("file", {count: 100, textTemplate: "`Количество: ${count}`"},  );

In the pug file:
p #{eval(textTemplate)}
gives an error count is not defined
however this will work:
- console.log(count)
p #{eval(textTemplate)}


That is, I'm interested in the dynamic insertion of content \ text in which there will be variables.

I didn’t find a better option than using eval.
If you tell me a more beautiful option, I will be grateful

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BestJS, 2022-04-12
@BestJS

pug doesn't set a variable if it doesn't see it in the file
The pug template has a locals variable that contains all the variables.
result:

res.render.call("file", {count: 100, textTemplate: "`Count: ${locals.count}`"}, );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question