My hosting provider automatically updated to 4.5 and it resulted in an error with the Visual Composer plugin.
I DID READ THESE POSTS: Plugin throwing TypeError after Wordpress 4.5 update
Visual composer doesn't load and gives TypeError: _.template(...).trim is not a function
Uncaught TypeError: $template.get is not a function
And replaced the html2element function with the one provided. However, as many people commented on these posts, I get a new error:
composer-view.js?ver=4.6.1:139 Uncaught TypeError: Cannot read property 'attributes' of undefined
Here is my function:
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()
},
The error seems to be coming from this line:
$template.get(0).attributes
Has anyone figured out how to fix it ?
Thanks for your help
My hosting provider automatically updated to 4.5 and it resulted in an error with the Visual Composer plugin.
I DID READ THESE POSTS: Plugin throwing TypeError after Wordpress 4.5 update
Visual composer doesn't load and gives TypeError: _.template(...).trim is not a function
Uncaught TypeError: $template.get is not a function
And replaced the html2element function with the one provided. However, as many people commented on these posts, I get a new error:
composer-view.js?ver=4.6.1:139 Uncaught TypeError: Cannot read property 'attributes' of undefined
Here is my function:
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()
},
The error seems to be coming from this line:
$template.get(0).attributes
Has anyone figured out how to fix it ?
Thanks for your help
Share Improve this question edited May 23, 2017 at 12:17 CommunityBot 11 silver badge asked May 7, 2016 at 15:55 Graham SlickGraham Slick 6,87011 gold badges55 silver badges91 bronze badges2 Answers
Reset to default 17Had the same problem with 4.5 update and tried everything I found but it was still not working.
Finally, I replaced my theme visual composer plugin (v4.7 something) by a recent one (4.11.2, google js_composer.zip).
I just replaced the entire directory content, it works fine.
Graham, hi
I think problem not in jquery, but in underscore that using in js_composer.
In render method pass wrong html object to html2element method like this:
this.html2element(_.template($shortcode_template_el.html(),
this.model.toJSON(),
vc.templateOptions.default));
But this code send to html2element method html object as function that not have any properties or something else. It happen because _.template function from underscore library not render first arg(html template) before second arg not have a valid variable for first arg.
In my opinion to solve this problem need do this:
this.html2element(_.template($shortcode_template_el.html()));
This 2 methods render and html2element https://gist.github.com/maximspokoiny/34ad60ad90944f8a80c6fc093873a807/9fb041d2b12249fe4391f986f4e7e6a08f57c6b3#file-gistfile1-txt
i using js_composer 4.7.4 and wordpress 4.5.2 and this solve problem.
Thanks!
UPDATED: Sorry, in html2element need too one change, from:
if ( _.isString( html ) ) {
this.template = _.template( html );
$template = $( this.template( this.model.toJSON(), vc.templateOptions.default ).trim() );
} else {
this.template = html;
$template = html;
}
to:
if ( _.isString( html ) ) {
this.template = _.template( html );
$template = $( this.template( this.model.toJSON(), vc.templateOptions.default ).trim() );
} else {
this.template = html;
$template = $( this.template( this.model.toJSON(), vc.templateOptions.default ).trim() );
}