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

Notifications? #151

Closed
jdarling opened this issue Jan 31, 2014 · 4 comments
Closed

Notifications? #151

jdarling opened this issue Jan 31, 2014 · 4 comments

Comments

@jdarling
Copy link
Contributor

Where would you tie in on your model or view controller to send notifications when a new one is created? I was trying to look through the SydJs example but I don't see exactly where this is done.

Would like to extend my existing blog, post, link, user signup, etc so that administrators get an email if they have signed up for the notification when an action occurs.

@JedWatson
Copy link
Member

I've just added an example email notification to admins when a draft post is created to the SydJS Site (It's been on my list for ages)

Check out the commit here to see how it works.

That commit doesn't include the email templates, which have been in place for a while.

You could easily bind the send to something other than the form submission in the view controller, for example, after the Post has been created, using middleware like this:

Post.schema.post('save', function() {
    if (this.wasNew && this.state == 'draft') {
        this.notifyAdmins()
    }
});

... however, I don't want it notifying anyone if someone creates a draft post in Keystone's Admin UI, which this would do. So I trigger it from the route handler.

In related news, the email functionality isn't really documented yet, but very cool: check out how SydJS is doing it.

We're using the keystone.Email class, which handles Mandrill for you, but also includes a default template which you can customise by

  • putting extends /layouts/default in your email template (this will actually extend the file keystone/templates/helpers/emails/layouts/default.jade)
  • setting the email locals config option, as is done by SydJS in the ./keystone.js file

Hope this helps.

@jdarling
Copy link
Contributor Author

jdarling commented Feb 4, 2014

Time to start hacking away :). We use Handlebars (converted from smarty) for all of our email templates and will be storing them in the DB. Looking at lib/email.js looks like you have hard coded to jade extension.

Can I suggest at some point that you look at moving Keystone to consolidate (https://github.com/visionmedia/consolidate.js) for easier support of any express template engine? Then it would truely be an option switch away. Jade isn't something that is easy for non-developers to pickup IMHO, and the users of the site I'm working on are used to their HTML WYSIWYG Email editor.

If I create an email2 module based on consolidate would you be interested in it?

  • Jeremy

@JedWatson
Copy link
Member

Hey Jeremy,

That's been on my list, the Email class really needs some love in the form of flexibility and docs.

Thanks for the offer to create an email2 module, I'd actually go one better and suggest you update the existing Email.js class to add support for consolidate.

The web views already support any engine that you can use with Express, either through the default support or by providing a custom engine.

For consistency, we should add a Keystone option called 'email engine' (to go with the 'view engine' option) and the Email class could decide from there. (You don't need to do anything special to add this, just refer to keystone.get('email engine') in Email.js and add it to the docs ;-)

If the option isn't set (or is set to jade), then it can use Jade as is currently implemented, so people can still use the custom extensions we've added for built-in templates.

@JedWatson
Copy link
Member

This is now covered by our yeoman generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants