[wp-trac] [WordPress Trac] #31281: Register JavaScript/Underscore templates using the WP Dependency API

WordPress Trac noreply at wordpress.org
Sun Feb 15 15:24:42 UTC 2015


#31281: Register JavaScript/Underscore templates using the WP Dependency API
---------------------------+------------------------------
 Reporter:  F J Kaiser     |       Owner:
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Script Loader  |     Version:  trunk
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------

Comment (by sanchothefat):

 Replying to [comment:6 F J Kaiser]:
 > > I'm thinking something like...
 > >
 > > {{{
 > > wp_script_add_data( 'handle', '<script type="text/x-javascript-hbs" id
 ="tmpl-xyz">{{ this.title }}</script>' );
 > > }}}
 > >
 > > It's then trivial to allow Backbone/Underscore-style templating, as
 well as anything else you want to achieve (meta tags, etc).
 >
 > I don't really get what you are aiming for with that (especially the
 "meta tags" part). Above would force me to fetch the file contents and put
 them into a callback.

 I agree with Ryan that if you're enqueueing templates it makes sense to
 allow passing in a script tag directly as well as a URL as I think there's
 a use case for generated templates.

 However I think Franz is right in that it's a still a script so
 `wp_enqueue_script()` makes sense - the templates will be dependencies of
 other scripts.

 I did wonder about things like meta tags where you might want to have some
 open graph tags dependent on others being present etc... or for removing
 their output by other plugins but the current `remove_action()`
 functionality is probably good enough. To get some progress on this my
 view is that it should be kept to the case of scripts where order of
 loading is more important.

 The same functionality could be offered for passing in a `<style>` tag to
 `wp_enqueue_style()` but again CSS dependencies aren't as much of an issue
 as they have to go in the `<head>` tag you can still use
 `remove_action()`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31281#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list