question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to use shared Layouts?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Globikcommented, Jun 14, 2017

@atuttle thanx for the link. But I also don’t want to repeat advertisment blocks in administrative parts of a site.

0reactions
kwallace0906commented, Mar 8, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Various ways of using Shared Layout in ASP.NET MVC
In this article we will discuss about various ways of using shared layout page in ASP.NET MVC applications. To experience it practically we ......
Read more >
MVC Shared layout between projects - Stack Overflow
Firstly, add your layout files to a new library which can be shared between your different projects. Then in each of your projects...
Read more >
What is Layout View in ASP.NET MVC - TutorialsTeacher
Layout views are shared with multiple views, so it must be stored in the Shared ... There are multiple ways to specify which...
Read more >
Layout in ASP.NET Core - Microsoft Learn
This article demonstrates how to: Use common layouts. Share directives. Run common code before rendering pages or views. This document discusses ...
Read more >
Create & Use Different Layouts for Different Pages | ASP.NET ...
create and use two or more layouts for different pages in asp.net mvcmanage more layouts in asp mvc 5use two different layouys in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found