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

WordPress Trac noreply at wordpress.org
Thu May 19 10:59:24 UTC 2016


#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:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------
Changes (by georgestephanis):

 * keywords:   => has-patch has-unit-tests


Comment:

 My VVV is currently down, so this will need someone to run the new test to
 confirm it's running -- but I just added 31281.diff -- I feel it's a more
 WordPress-y way of doing this.

 In short, devs can either call `wp_script_add_template( 'handle', 'id',
 'template' );` or `$wp_scripts->add_template()` with the same arguments.
 The seconds argument gets auto-prefixed with `tmpl-` as per normal
 WordPress and `wp.template()` standards, and the generated template prints
 out with the script (or before, in the case of concatenations).

 It feels much more similar to `wp_add_inline_style()` and the like in
 behavior.

 Oh, and as an added bonus, `wp_script_add_template()` can be called
 multiple times, and it will just add additional templates to the script in
 question -- unlike `->add_data()` and such, which will replace the prior
 content with the new.

 Also, as it takes in a string, instead of a file path, we avoid either
 subsequent loads client-side and filesystem hits as per @nacin's concern
 above.

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


More information about the wp-trac mailing list