April 20, 2016

How to use the underscore.js templates in WordPress?

WordPress 4.5 is released with lot of new updates, but our clients pointed out that some of shortcodes from our Awesome Easy Bootstrap Shortcode stop working such as Tabs, Accordion etc.

This happened due to the latest update to core undescore.js file from 1.7 to 1.8.3. and as per the new update

Underscore templates no longer accept an initial data object. _.template always returns a function now.

This means that we can’t use the following code

var item = _.template(<template_name>, <data-object>);

We have to use this code

var item = _.template(<template_name>);
item = item(<data-object>);

So this is the way to use underscore templates in the latest underscore.js

Leave a Reply