javascript cross plugin interference


I have created two plugins using Tom McFarlin’s Boilerplate template; both use Javascript and REST. Each works fine independently. Each creates a short code and each short code is used on independent pages. Plugin two contains:

 app.PilotHeader = Backbone.View.extend({
  el: '#pdf_header',
    template: _.template($('#header-template').html()),
    initialize: function(){
  render: function(){
    this.$el.html(this.template(this.model.toJSON() ));
    return this;

When plugin one runs I get an error on the line template: _.templates… line in plugin two. It can’t find ‘#header-template’ which is in an external HTML file. The template is small enough that I can include it directly as a work around.
Two questions:
1) How do I prevent the javascript code from two different plugins from being intermixed like this?
2) Why can’t Javascript find the template?

, , dsj 4 years 2020-03-03T11:51:12-05:00 0 Answers 101 views 0

Leave an answer