-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Include issue #20
Comments
Hi! Thank your for checking out Fastify! |
Hi Tomas, For sure, check out here: All the EJS files are located in the same "views" folder, but resulting in the same error: I have tried implement the EJS include function in different ways, but can't find the right relative path. This example works fine in Express, but would for sure like to test Fastify :-) Thanks. |
If you are using 'use strict'
const fastify = require('fastify')()
const resolve = require('path').resolve
fastify.register(require('point-of-view'), {
engine: {
ejs: require('ejs')
},
options: { // this object will be passed to ejs.compile
filename: resolve('views')
},
templates: 'views'
})
fastify.get('/', (req, reply) => {
reply.view('/index.ejs', {})
})
fastify.listen(3000, (err) => {
if (err) throw err
console.log(`Server up: ${fastify.server.address().port}`)
}) |
Hi again, Unfortunately the filename within the "fastify.register" options didn't work. I couldn't print the variable in the EJS file or use it in the EJS include function. The only way to make it work is by adding the resolved path in the "reply.view", but it's not a pretty solution. Any ideas on fixing it? JS EJS Thanks. |
I have answered in your gist. In that way everything works. :) |
Super, didn't spot it. Much better! Thanks for solving it Tomas 👍🏻 |
You're welcome! If you have more questions or suggestions please open other issues! |
Hi all, I spent a lot of time on the same problem ... thanks a lot for the comments in the gist. |
Sandro, the best approach would be if you open up a PR with the doc/example you think we are missing! |
Hi Matteo, I'll do that. Thanks for now. |
Hi guys,
Have any of you got troubles with including other EJS components within an EJS file? I'm getting following error "Error: Could not find include include file.".
Example:
<% include header %> within the "index.ejs" file.
It works in Express, so maybe I just can't find the relative path somehow. All my ejs files is located in the same folder, so shouldn't be an issue.
Thanks.
The text was updated successfully, but these errors were encountered: