Is there a way to use shared Layouts?
See original GitHub issueI really love this template engine but I’m struggling trying to figure out how to wrap everything in a common/shared layout file.
I’m making use of the express feature where you can set the views location to an array of paths.
views - String or Array - A directory or an array of directories for the application’s views. If an array, the views are looked up in the order they occur in the array.
So for example, I’m setting views to: [ '/usr/src/app/debug/views', '/usr/src/app/root/views' ]
With this configuration, I can’t even get simple partials working. Given view debug_home
(in the debug/views folder):
debug home template<br/>
${ foo }
And a partial view foo.html
(in the root/views folder):
hello, world
And the following code in a route:
return res.render( 'debug_home', { partials: { foo: 'foo' } } );
I get the following error response:
Error: Error: ENOENT: no such file or directory, open ‘/usr/src/app/debug/views,/usr/src/app/root/views/foo.html’ at ReadFileContext.getFileContent [as callback] (/usr/src/app/node_modules/express-es6-template-engine/es6-renderer.js:11:61) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:366:13)
Perhaps this is an oversight from not anticipating that the views location setting might be an array?
If I switch the route handler code to:
return res.render( 'debug_home', { partials: { foo: 'foo.html' } } );
The the error changes to:
Error: Error: ENOENT: no such file or directory, open ‘foo.html’ at ReadFileContext.getFileContent [as callback] (/usr/src/app/node_modules/express-es6-template-engine/es6-renderer.js:11:61) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:366:13)
I see this note in the project readme:
All templates files paths are defined as absolute to the root directory of the project.
But I’m not sure if that is specific to partials or something else. If I change my route handler to the following:
return res.render( 'debug_home', { partials: { dump: '/usr/src/app/root/views/foo.html' } } );
Then the partial renders, but this can’t be the intended approach, can it? This seems like a bad idea. Was that just a shortcut to get this proof of concept out there, or is it intended to be a long term solution?
Partials aside, I’m still trying to figure out the best way to do shared layouts. Can you offer any guidance there?
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (4 by maintainers)
Top GitHub Comments
@atuttle thanx for the link. But I also don’t want to repeat advertisment blocks in administrative parts of a site.
Hey @dondido I have a question about your WebRTC room and this was the only way I could contact you. If have a website application already in place (built with React and Vanilla PHP), but would like to add in a page that utilizes the WebRTC chatroom, would this be possible to instantly start adding in that page to the site? Hopefully you see this.