-
Notifications
You must be signed in to change notification settings - Fork 87
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
Support for layout template files & Code clean-up #165
base: master
Are you sure you want to change the base?
Conversation
- render() always returns HTML since c37582b - views() returns a function which can be used either as koa middleware or as a simple getter to extend the context
npm also upgraded the lockfile to version 2
Is this project still maintained? |
@kellnerd Sorry, I stopped using koa a long time ago and I cannot support the package with my current capacity. Would you like to step in as a maintainer? At a quick glance, the PR looks solid and makes total sense. what do you guys think @int64ago & @niftylettuce? |
Thank you for the honest response @queckezz. I haven't published anything on npm so far, so I'm not sure whether I would be a good maintainer. But given that I'm using the package for at least one project, I will read the npm docs and try my best. As this PR gives the |
We are maintaining a new fork at https://github.com/ladjs/koa-views of this project - feel free to submit PR/work there. Thank you. |
This PR adds support for a layout file which can be used as a shared top-level template to have a common page structure into which the rendered template will be inserted. This is useful for template engines which do not have native support for layout files, e.g. EJS.
Layout support can be enabled by passing the name of a layout file to the rendering context/state in the
layout
property. This layout template will then have access to the same state as the current template, for whichrender()
has been called. Instead of directly returning the resulting HTML of the current template, it will be passed to the layout in thebody
property and the resulting HTML of the layout will be returned.Example:
foo.ejs:
simple_layout.ejs:
The PR also updates the type definitions, drops an unused dependency and refactors the code to use
async
/await
(requires node v7.6+ which koa v2 needs anyway) instead of promise chaining to make the code easier to understand (or to extend, as I did here).See the individual commit messages for details.