V
V
Violetta Morozova2018-01-26 22:30:15
JSON
Violetta Morozova, 2018-01-26 22:30:15

Using json in conjunction with pug with Grunt builder?

Everywhere I find information on this issue, but with answers: how to configure gulp so that pug eats data files. But I need Grunt settings, and I can't even find such articles. Grant is dead? Okay, this is a rhetorical question.
1) People, does anyone know if it is possible to set up a bunch of json to pug in Grant? If so, how?
2) I tried to register in the config

data: {
        jobs: grunt.file.readJSON('src/etvm/facts.json')
      }

But it gave an error
Unexpected token c in JSON at position 2
What could be the problem? What am I doing wrong? What is this symbol c ?
3) And besides, I decided to try to do without files and write data to a variable directly in the pug file.
- var facts = [
    {
      "question": "текст",
      "answer": "вот такой вот текст",
      "answer_two": "большой текст"
    },
    {...}
]

each fact in facts
  h3.facts__title !{fact.question}

But in the console, grunt gives an error:
>>     1| - var facts = [
>>  > 2|     {
>> ---------^
unexpected text "{

What could be the problem? What am I doing wrong? Here , a person succeeds in everything, but I don’t :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2018-01-26
@vilka_2009

Grant is dead?

Yep. And how long.
Invalid JSON, show file. Or, perhaps, an error in the path to the file, xs how does grunt.file.readJSON work there. Try './src/etvm/facts.json'.
pug does not understand this, the whole expression - varmust go in one line.
You are on the right track, only something with reading json did not work for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question