[wp-trac] [WordPress Trac] #31281: Register JavaScript/Underscore templates using the WP Dependency API
WordPress Trac
noreply at wordpress.org
Sun Feb 15 13:19:56 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 F J Kaiser):
Replying to [comment:4 rmccue]:
> The patch here needs to be in 5.2 syntax, so no `\`s in the class names
please. Also, needs to follow WP bracing style. :)
Done - thanks for the hint. I completely forgot about that. New patch also
checks the edge case if there's actually an extension, if not it returns
whatever was added.
> Also, as I noted on #31273, I think it'd be more valuable to allow just
adding arbitrary HTML to tags via `WP_Dependencies::add_data`.
Alternatively, a different dependency chain should be used rather than
attaching this on top of the WP_Scripts one.
It's just attached to a filter and is completely ''inline'' with the
Dependency API. There's no "on top of the `\WP_Scripts` one". Goal was to
treat script templates as what they are: Dependencies like other JS
scripts or Stylesheets. That's exactly what happens.
> 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. That's pretty much what I wanted to avoid and why it
happens in the callback. Also, please note that templates are ''tightest''
connected to scripts (views for example) and therefore need to reliably
get included when the view is included. This puts a lot of burden off the
shoulders of any developer. Register your view, Register your template and
just enqueue your view whenever you need it - the rest is plain core WP
Dependency API magic. Bonus: No one needs to learn anything new and can
just jump on it.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31281#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list