Uncaught TypeError: $ template.get is not a function

I get this error in WordPress when I use a plugin called WpBakery Visual Composer.

I am using the latest version of WordPress (4.5), using the latest version of Google Chrome, and all plugins are updated. It seems I cannot add any elements or patterns using Visual Composer.

Can someone help me or tell me what could be and how I can fix this error.

The error I get is:

enter image description here

+32
javascript jquery wordpress
Apr 15 '16 at 8:07
source share
7 answers

Please see my answer here.

I fixed this error by updating the html2element function to:

 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() }, 

in /wp-content/plugins/js_composer/assets/js/backend/composer-view.js

or in wp-content / plugins / js_composer / assets / js / dist / backend.min.js`

Hope this works for you!

+86
Apr 15 '16 at 17:16
source share

@Sorin Haidau

Hi guys, I'm using the Astra theme. This fix works for 99.9%. For some, this only stops the spinning wheel, but as soon as the page loads the visual composer, no.

I modified this code a bit (which is now posted everywhere)

The original Astra theme code is here (composer-view.js)

  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) { attributes[attr.name] = attr.value; }); this.$el.attr(attributes).html($template.html()); this.setContent(); this.renderContent(); }, 

Code that works:

 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 main difference is here (compared to the source code)

 }); this.$el.attr 

Instead of the original comma there is a semicolon :):

 }), this.$el.attr 

Greetings from people :)

Update: this recorded about 19 of the 20 sites that I had with the astra theme with the same error as mentioned above ... all but one site.

I had this error after the visual composer finally appeared (half of the design elements are missing)

 Uncaught Error: Syntax error, unrecognized expression: .ui-tabs-nav [href=#tab-1415196282-1-8] 

I fixed this by updating line 552 of composition-custom-views.js:

 $('.ui-tabs-nav [href="#tab-' + params.tab_id + '"]').text(params.title); 

And voila, everything now works. I'm sorry if it does not work for all topics, try using the code mentioned above. If this does not work, try my solutions :)

+16
Apr 28 '16 at 21:24
source share

Someone posted on the WordPress forum this solution that worked for me.

Replace the html2element function in /wp-content/plugins/js_composer/assets/js/backend/composer-view.js following text.

 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() }, 

Edit: I had to make this replacement a second time under different circumstances, and it did not start until I disconnected and then turned on the Visual Composer plugin and the Ultimate Visual Composer add-in again.

+9
Jun 22 '16 at 21:26
source share

The funny thing is ... my version number of the visual composer was much higher than the last update (4.8. *).

In any case ... I had the same problem and the previous answers did not completely solve my problems, so I decided to try and buy a new copy of the plugin. It worked out well.

Now I can confirm that version 4.12.1 of Visual Composer works with WordPress 4.6.1 without errors.

Also pay attention to this:

The latest version of Visual Composer does not have a directory like backend or a file called composer-view.js .

PS. Using these graphic page designers sucks ***.

+2
Oct 21 '16 at 8:36
source share

Noticed that the code was not passed to the html2element function, but existed in the function calling it (render)

The following code completely fixed my problems, I can load the page, add, clone, delete, etc.

 render: function () { var $shortcode_template_el = $( '#vc_shortcode-template-' + this.model.get( 'shortcode' ) ); if ( $shortcode_template_el.is( 'script' ) ) { var newHtmlCode = _.template( $shortcode_template_el.html(), this.model.toJSON(), vc.templateOptions.default ); if(!_.isString(newHtmlCode)){ newHtmlCode = $shortcode_template_el.html(); } this.html2element( newHtmlCode ); } else { var params = this.model.get( 'params' ); $.ajax( { type: 'POST', url: window.ajaxurl, data: { action: 'wpb_get_element_backend_html', data_element: this.model.get( 'shortcode' ), data_width: _.isUndefined( params.width ) ? '1/1' : params.width, _vcnonce: window.vcAdminNonce }, dataType: 'html', context: this } ).done( function ( html ) { this.html2element( html ); } ); } this.model.view = this; this.$controls_buttons = this.$el.find( '.vc_controls > :first' ); return this; }, 
+1
Oct 10 '16 at 13:14
source share

last patch in December 2016, for Visual Compoder fix this,

 html2element:function(html){var $template,attributes={},template=vc.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()}, 

pay attention to this important thing, template = vc.template (html); in the actual code. This is a quick fix in the latest version, compatible with the latest WPordpress.

Remember to update Wordpress and the theme accordingly, so this fix should work fine.

thanks and happy coding

0
Dec 13 '16 at 6:46
source share

for everyone who comes here from a Google search: after changing the html2element function, if you have this error Unable to read the attribute attributes' update render: function below code

 render: function () { var $shortcode_template_el = $( '#vc_shortcode-template-' + this.model.get( 'shortcode' ) ); if ( $shortcode_template_el.is( 'script' ) ) { var newHtmlCode = _.template( $shortcode_template_el.html(), this.model.toJSON(), vc.templateOptions.default ); if(!_.isString(newHtmlCode)){ newHtmlCode = $shortcode_template_el.html(); } this.html2element( newHtmlCode ); } else { var params = this.model.get( 'params' ); $.ajax( { type: 'POST', url: window.ajaxurl, data: { action: 'wpb_get_element_backend_html', data_element: this.model.get( 'shortcode' ), data_width: _.isUndefined( params.width ) ? '1/1' : params.width, _vcnonce: window.vcAdminNonce }, dataType: 'html', context: this } ).done( function ( html ) { this.html2element( html ); } ); } this.model.view = this; this.$controls_buttons = this.$el.find( '.vc_controls > :first' ); return this; }, 
-one
Jan 12 '17 at 4:51 on
source share



All Articles