Express Sweet API Reference - v3.0.0
    Preparing search index...

    Class View

    Enable Handlebars template engine with custom helpers and configuration. Sets up view engine, layouts, partials, and before-render hooks.

    // View configuration in config/view.js
    export default {
    views_dir: 'views',
    partials_dir: 'views/partials',
    layouts_dir: 'views/layout',
    default_layout: 'views/layout/default',
    extension: '.hbs',
    beforeRender: (req, res) => {
    res.locals.extra = 'Extra';
    }
    };
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Mount Handlebars view engine on Express application. Configures template engine, helpers, layouts, and partials.

      Parameters

      • app: Express

        Express application instance

      Returns Promise<void>

      // This method is called automatically by express-sweet.mount()
      import View from './middlewares/View';

      await View.mount(app);
    • Mount middleware to be executed just before rendering the view. Allows setting view variables and executing beforeRender hooks from configuration.

      Parameters

      • app: Express

        Express application instance

      Returns Promise<void>

      // Called automatically after authentication middleware setup
      await View.mountBeforeRender(app);