Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add data.json to pug rendering? #96

Open
afknapping opened this issue Nov 3, 2018 · 1 comment
Open

how to add data.json to pug rendering? #96

afknapping opened this issue Nov 3, 2018 · 1 comment

Comments

@afknapping
Copy link
Contributor

I wonder how I can pass data into the pug rendering process.

I found this:

...with something like render(view, { locals: { projects: myObjectHere }})

but would want to have that in a seperate json or even better yml file.

if that is not currently possible (which i guess), where would i hack that in? for example, i found pug being mentioned in node_modules/@pingy/compile/lib/compile.js but not sure where or how to continue from there...

My usecase is having text snippets I want to use consistently through the UI and change them in one place only... like the copy "continue" in some buttons and the like...

@davej
Copy link
Member

davej commented Nov 3, 2018

Yes, it's not supported. Happy to take PRs though because it's a useful feature.

If you wanted to pass in extra options to Pug then you would add it to the transpilerOptions object here.

You could do something like check if the engine is pug and then search for a json file that has your locals in it.

if (adapter.engineName === 'pug') {
  const parentDir = path.basename(pathName)
  const dataPath = path.join(parentDir, 'data.json')
  // TODO: Check if dataPath exists and is valid JSON
  // TODO: If it exists then read the json and add it to `transpilerOptions`
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants