Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does Hapi support multiple view templates? #1322

Closed
leore opened this issue Jan 12, 2014 · 8 comments
Closed

Does Hapi support multiple view templates? #1322

leore opened this issue Jan 12, 2014 · 8 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@leore
Copy link

leore commented Jan 12, 2014

Is there an example out there if it does?

@hueniverse
Copy link
Contributor

@leore
Copy link
Author

leore commented Jan 13, 2014

Sorry to clarify. I meant does hapi support multiple layouts for a single template engine (im using handlebars).

I see that to enable a layout I create a layout.hbs but what if I have 2 layouts. layout1.hbs and layout2.hbs. How can I tell the view render which layout to use.

@hueniverse
Copy link
Contributor

You will need to override the layout when you call view(). It's one of the options. You can setup one as the default.

@leore
Copy link
Author

leore commented Jan 13, 2014

How can I overwrite. The layout parameter is a boolean. I cannot pass a layout. The layout parameter should take a layout file not a boolean.

@hueniverse hueniverse reopened this Jan 13, 2014
@ghost ghost assigned hueniverse Jan 17, 2014
@leore
Copy link
Author

leore commented Jan 17, 2014

Eran,

!תודה רבה

2.0.0 works like a charm but 1 small bug. Line 1783 in response.js. If you explicitly change true to 'otherLayout' it wont work. The fix allows alternative layouts when you use reply.view but not in the server config.

You get an error: [1] the value of layout must be a boolean.

I and most people also usually have layouts in a separate folder than most of my views. Would be great to add a layoutsPath to the server config like you have for partialsPath.

Below is the test that fails


it('returns response with layout override', function (done) {

    var layoutServer = new Hapi.Server({ debug: false });
    layoutServer.views({
        engines: { 'html': 'handlebars' },
        path: __dirname + '/../unit/templates',
        layout: 'otherLayout'
    });

    var handler = function (request, reply) {

        return reply.view('valid/test', { title: 'test', message: 'Hapi' }, { layout: 'otherLayout' });
    };

    layoutServer.route({ method: 'GET', path: '/', handler: handler });

    layoutServer.inject('/', function (res) {

        expect(res.result).to.exist;
        expect(res.statusCode).to.equal(200);
        expect(res.result).to.equal('test:<div>\n    <h1>Hapi</h1>\n</div>\n');
        done();
    });
});

@leore
Copy link
Author

leore commented Jan 19, 2014

Do you have an example with this new code where I can use 2 templates. 2.1.x solved most of my issues but I cant seem to specify my layout when I create a new route. It keeps using my default.

It might be because my syntax is wrong but Im not getting an error

@leore
Copy link
Author

leore commented Jan 19, 2014

never mind...got it. 2.1.x working great with multiple layouts.

jmonster pushed a commit to jmonster/hapi that referenced this issue Feb 10, 2014
@Marsup Marsup added feature New functionality or improvement and removed request labels Sep 20, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants