Comments (12)
You can do layouts like this:
home.hbs
:
layout.hbs
:
app.js
:
module.exports = async function (fastify, opts) {
fastify.register(require('point-of-view'), {
engine: { handlebars: require('handlebars') },
options: { partials: { layout: 'layout.hbs' } }
});
fastify.get('/', async (request, reply) => {
reply.view('home.hbs');
});
};
from point-of-view.
@chinhtrandn
according to tests, yes
point-of-view/test/test-handlebars.js
Line 604 in f218d2e
from point-of-view.
Can you make an example we can work with? Maybe point-of-view is missing some features!
from point-of-view.
Done, here is a small example: https://github.com/AragurDEV/fastify-point-of-view-example
from point-of-view.
Unfortunately I don't know how to help, as I'm not super familiar with handlebars. A PR would be welcome.
from point-of-view.
I've been trying to figure out this problem too. I think it has to deal will how the view engine is set up right now. I compared the engine express-handlebars uses and the one point of view uses. In summary, the express-handlebars render twice. One for the main then one for the layout to put in the main body. Meanwhile, point-of-view is set to only render one template it seems. So if you want something like express-handlebars your best bet right now is writing a plugin that handles that double compile-rendering process. Unfortunately, I have no idea where to begin. I don't know enough handlebars to even begin to make such a plugin.
from point-of-view.
Since layouts are a handlebar-express
-package-specific feature, I think this could only be achieved by doing the two-step-render process @nikea1 described at the handler-level, e.g:
fastify.get('/', async (request, reply) => {
const html = await fastify
.view('home.hbs', {})
.then(body => fastify.view('layout.hbs', { body, title: 'It works!' }))
reply.type('text/html').send(html)
})
given a templates/layout.hbs
like this:
and a templates/home.hbs
like this:
--
I could open a PR to "bake" this functionality into point-of-view
plugin, if it makes sense @mcollina
from point-of-view.
I think that make sense, send a PR over. However we need to make sure that either:
- we throw nicely for other engines
- we implement some similar feature for them
from point-of-view.
Handlebars supports layouts via partial blocks and inline partials.
from point-of-view.
Handlebars supports layouts via partial blocks and inline partials.
Could you elaborate?
I don't understand the point
from point-of-view.
Can i set Partials folder?
from point-of-view.
#136 and #141 implemented this issue
closing
from point-of-view.
Related Issues (20)
- Type of templates property in PointOfViewOptions show allow arrays HOT 1
- Allow custom `Content-Type` header for Nunjucks HOT 1
- How to render view dynamically by http status on ExceptionFilter HOT 1
- Nunjucks templates do not dynamically reload in development HOT 4
- could you add support of svelte? HOT 1
- support for async minify methods HOT 3
- eta v3 integration doesn't work HOT 1
- nunjucks custom filter is not working HOT 1
- I am getting the following error after installing and configuring the lib: reply.view is not a function HOT 2
- Latest version of Eta no longer works HOT 6
- Support for view raw text
- `fastify.view` is rendered without `reply.locals` HOT 18
- Swig support HOT 3
- Like operator not works on return reply.view HOT 7
- Postgresql's like operator not works on return reply.view HOT 1
- Fastify app not updating pages unless another route is added HOT 1
- When `onError` hook is defined, failure to compile template crashes server (ejs) HOT 4
- Proposal: Remove `send` calls HOT 4
- Support absolute paths for `layout` and `partials` properties for Handlebars HOT 2
- edge.js templates HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from point-of-view.