fastify / point-of-view

Template rendering plugin for Fastify
MIT License
335 stars 86 forks source link

Support for view raw text #390

Closed sirenkovladd closed 10 months ago

sirenkovladd commented 10 months ago

Prerequisites

🚀 Feature Proposal

Call reply.view with raw text or a callback function

Motivation

Projects can use precompiled templates

Projects can use a generated template that can be received from an external source, you can avoid saving the template to a file

Example

fastify.get('/', async (req, reply) => {
    const rawTemplate = await someRequestOrQuery(req)
    const someData = await getSomeData(req)
    reply.view({ raw: rawTemplate }, someData)
})
fastify.get('/', async (req, reply) => {
    const rawTemplate = await prepareHbsTemplate(req)
    const template = hbs.template(rawTemplate) // typeof template === 'function'
    const someData = await getSomeData(req)
    reply.view(template, someData, { layout: someLayout })
})