How to fix “Uncaught TypeError: $template.get is not a function” in Visual Composer

Sometime before when my site updated WordPress version 4.5. I get a issue with “Uncaught TypeError: $template.get is not a function” in Visual Composer plugin.

I’m debugging and search with error message and found an answer help me fixed this bug by updating the html2element function in file /wp-content/plugins/js_composer/assets/js/backend/composer-view.js from:

/**
 * Convert html into correct element
 * @param html
 */
html2element: function(html) {
  var attributes = {},
    $template;
  if (_.isString(html)) {
    this.template = _.template(html);
    $template = $(this.template(this.model.toJSON()).trim());
  } else {
    this.template = html;
    $template = html;
  }
  _.each($template.get(0).attributes, function(attr) { // **errors on this line**
    attributes[attr.name] = attr.value;
  });
  this.$el.attr(attributes).html($template.html());
  this.setContent();
  this.renderContent();
},

To code below:

html2element: function(html) {
            var $template, attributes = {},
                template = html;
            $template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
                attributes[attr.name] = attr.value
            }), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
},

 

Related Posts

About The Author

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.