What is in media-template.php, and how does it work?

Those are javascript templates that get compiled into HTML by a javascript library. I think WP uses underscore.js.

Let’s say you write a jQuery plugin, and you have to append HTML code to the document. Using such templates you can avoid stuffing that HTML code inside huge concatenated strings within your javascript code, and put it where the other HTML markup is. So you load that template from your plugin, compile it (variables get replaced) and append the resulting HTML to your document. Essentially you separate the business logic from the presentation logic. This also makes your plugin more decoupled.

Leave a Comment