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

Idea: Notice templates #6

Open
JasonTheAdams opened this issue Oct 18, 2024 · 3 comments
Open

Idea: Notice templates #6

JasonTheAdams opened this issue Oct 18, 2024 · 3 comments

Comments

@JasonTheAdams
Copy link
Contributor

The standard WP notice is nice, but not particularly inspiring. Some products want to use their own style of notification — that's branded or just more modern looking. Right now a callback can be used for the notice content without the wrapper to accomplish this, but it's more cumbersome to do. It would be cool to have a formal templating system!

I'm imagining something like the following:

AdminNotices::registerTemplate('pretty-template', PrettyTemplate::class)

AdminNotice->show('pretty-notice', 'Hello world!')
  ->template('pretty-template')

This would keep the syntax nice and simple. It might be cool to also have:

AdminNotices::setDefaultTemplate('pretty-template');

AdminNotice::show('pretty-by-default', 'So pretty!');
AdminNotice::show('default', 'Using the default template')
  ->defaultTemplate();
@JasonTheAdams
Copy link
Contributor Author

This would mean introducing:

  • NoticeTemplateInterface interface
  • NoticeTemplateRegistrar registrar
  • DefaultNoticeTemplate as the default used

I'm imagining the interface will be something like:

interface NoticeTemplateInterface {
    public function render(AdminNotice $notice, array $wrapperAttributes, array $dismissClasses)
}

While the template could derive the attributes and classes itself from the notice, I feel like providing them directly would help future-proof any changes to them, as well as handle the namespacing so the template doesn't have to worry about that.

Should the namespace be provided to the template? Perhaps for adding their own things, but since it's custom already it may just be unnecessary as the namespacing is most important for built-in features.

@slaFFik
Copy link

slaFFik commented Oct 18, 2024

I would say that namespacing for templates isn't needed. Notices have ids, devs can use whatever they want there to differentiate notices, templates are custom code - managed by devs as well, so imo we are good.

@JasonTheAdams
Copy link
Contributor Author

Thanks, @slaFFik! Yeah, I'm leaning more in that direction.

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