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

request.server._views in plugin #1795

Closed
futurechan opened this issue Jul 21, 2014 · 6 comments
Closed

request.server._views in plugin #1795

futurechan opened this issue Jul 21, 2014 · 6 comments
Assignees
Labels
Milestone

Comments

@futurechan
Copy link

@futurechan futurechan commented Jul 21, 2014

I was calling request.server._views.render to render some html server-side, which was working great. Now I have moved this to a plugin, but I can't seem to find the right _views object. What am I missing?

Similarly, how do I access plugin.app from a handler declared within the plugin. https://github.com/spumko/hapi/blob/master/docs/Reference.md#pluginapp

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Aug 4, 2014

First, don't call anything starting with an _ because it is not a supported API. I am likely to change those frequently. You should use the reply.view() method.

As for plugin.app, it is not accessible unless you use plugin.expose(). I like plugin.bind() best. in general, plugin.app is a place for the plugin to maintain its own state, but it is not as useful as the other options above.

@hueniverse hueniverse closed this Aug 4, 2014
@hueniverse hueniverse self-assigned this Aug 4, 2014
@futurechan
Copy link
Author

@futurechan futurechan commented Aug 4, 2014

@hueniverse I'm not trying to return the rendered view in an http response. I am trying to build a simple email template service that accepts a json payload, renders the html, and sends out the email via an smtp server.

Is there a way to access the rendered html after reply.view() is invoked?

Regarding plugin.bind(), that's what I ended up using. However, I am wanting to pass my smtp service wrapper to a few plugins. plugin.app looked a little cleaner rather than picking it off the request object.

@hueniverse hueniverse reopened this Aug 5, 2014
@hueniverse hueniverse added this to the 6.5.0 milestone Aug 5, 2014
@hueniverse hueniverse closed this in 88a2fef Aug 5, 2014
@futurechan
Copy link
Author

@futurechan futurechan commented Aug 5, 2014

@hueniverse Awesome!

By the way, in the case that my handler is in a different file, what's the best way to share the plugin. Right now, I have a setup method that is exported. I call that method and pass the plugin in. It's a little messy, but I'm not sure what else to do.

Also, request.server.render throws an expection stating request.server has no method render(). Similarly, I passed plugin to the module that contains my handler and used plugin.render(). I got the same error.

I am running hapi 6.4.

@futurechan
Copy link
Author

@futurechan futurechan commented Aug 5, 2014

@hueniverse Super sorry. I just saw the 6.5 in the commit. Do you know when npm will be updated?

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Aug 6, 2014

@futurechan use plugin.bind()

@Marsup Marsup added feature and removed request labels Sep 20, 2019
@lock
Copy link

@lock 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants