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

    Interface ViewConfig

    Handlebars view engine configuration interface. Defines configuration for template directories, layouts, partials, and rendering hooks.

    // 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.siteName = 'My Website';
    res.locals.currentYear = new Date().getFullYear();
    }
    };
    interface ViewConfig {
        views_dir?: string;
        partials_dir?: string | string[];
        layouts_dir?: string;
        default_layout?: string;
        extension?: string;
        beforeRender?: (req: Request, res: Response) => void | Promise<void>;
    }
    Index

    Properties

    views_dir?: string

    Absolute path to the directory where the view files are located, defaults to <application root directory>/views.

    partials_dir?: string | string[]

    Path to partials templates, one or several directories, defaults to <application root directory>/views/partials.

    layouts_dir?: string

    Path to layout templates, defaults to <application root directory>/views/layout.

    default_layout?: string

    Absolute path to default layout template. defaults to <application root directory>/views/layout/default.hbs.

    extension?: string

    Extension for templates & partials, defaults to .hbs,

    beforeRender?: (req: Request, res: Response) => void | Promise<void>

    Hook function just before the view is rendered. For example, you can set your own local variables that can be used within the view.

    // The message set here can be referenced in the view as {{message}}.
    beforeRender: (req, res) => {
    res.locals.extra = 'Extra';
    }