Articles of underscore

What type of template are WP media-modal's templates?

I was looking at the WordPress templates (html that’s written to the page instead of awkwardly adding strings in JS). There are a lot of templates like this in a post editor for example: <script type=”text/html” id=”tmpl-uploader-status-error”> <span class=”upload-error-filename”>{{{ data.filename }}}</span> <span class=”upload-error-message”>{{ data.message }}</span> </script> Now, I know these can be referenced with‘uploader-status-error’)( […]

WP Customizer JS Template not saving color field

I’m trying to create a custom typography control, I’m having problem saving the value of the color, please take a look at my code: <?php class Customizer_Typo_Control_Typography extends WP_Customize_Control { /** * The type of customize control being rendered. */ public $type = ‘typography’; /** * Array */ public $l10n = array(); /** * Set […]

Open media frame and select an attachment

I’m using the following piece of code to open a media frame when clicking a link with a data-attachment_id attribute. This attribute holds the id of an attachment that I want to select when the frame opens: jQuery(document).ready(function($){ $( ‘#gallery_images_container’ ).on( ‘click’, ‘a.edit’, function( event ) { var $el = $( this ); var selected […]

Can I add custom attributes while adding inline scripts?

I need to inject some underscore templates into admin screen without modifying the core. The templates look like this: <script type=”text/template” id=”template-123″> <div class=”section intro”> {{{ data.section.intro }}} </div> <div class=”section content”> {{{ data.section.content }}} </div> … </script> All templates depend on certain script handle, so I thought about using wp_add_inline_script() but it doesn’t allow […]

Using Underscore Templates in WordPress

I’ve noticed that since WP 3.5 that we now have the Backbone.js and Underscore.js libraries included. The new Media Modal uses Underscore templates and I was wondering how would I be able to insert them, especially in the admin side of things.Is there a correct way to insert these?