koajs / koa-hbs

Handlebars templates for Koa.js
MIT License
159 stars 43 forks source link

how to do render theme view? #54

Closed einsqing closed 7 years ago

einsqing commented 7 years ago

how to do render theme view?

shellscape commented 7 years ago

Not quite sure what you're asking there. Please rephrase and elaborate.

einsqing commented 7 years ago

like this

router.use('/home', home.routes(), function *(next) {
    hbs.configure({
        viewPath: path.resolve(__dirname, path.normalize('./../view/home')),
        layoutsPath: path.resolve(__dirname, path.normalize('./../view/home/layout')),
        partialsPath: path.resolve(__dirname, path.normalize('./../view/home/partial')),
        defaultLayout: layout,
        extname: '.html',
        disableCache: true
    });

    yield next;
});
router.use('/admin', admin.routes(), function *(next) {
    hbs.configure({
        viewPath: path.resolve(__dirname, path.normalize('./../view/admin')),
        layoutsPath: path.resolve(__dirname, path.normalize('./../view/admin')),
        partialsPath: path.resolve(__dirname, path.normalize('./../view/admin')),
        defaultLayout: layout,
        extname: '.html',
        disableCache: true
    });

    yield next;
});

I want to render diffrent theme and like this is wrong.so what do i do?

shellscape commented 7 years ago

All layouts have to be in the same directory. You can layer the directory, but at this time they all have to be in one. (partialsPath is the only path option that supports an array of paths) Then, to use different layouts., reference the README:

In addition to, or alternatively, you may specify a layout to render a template into. Simply specify {{!< layoutName }} somewhere in your template. koa-hbs will load your layout from layoutsPath if defined, or from viewPath otherwise.