Expert Group of programming
Loading...

Uncaught TypeError: $template.get is not a function – Visual composer issue

Posted by : Heycode Tech | Posted in : Visual Composer, WordPress Plugins | Mar 30,2017 | 0 comments

I have received a lot of emails regarding the :visual composer problem : once we update the : WordPress version: or anything.

 

 

Now the issue is :Uncaught TypeError: $template.get is not a function :. Once this error occurs then your visual composer is not loaded and will display something like this.

 

 

Solution 1 :Change the function: html2element

For resolving this issues, we need to change the function : html2element : in files.
> composer-view.js, File path: /wp-content/plugins/js_composer/assets/js/backend/composer-view.js:

Your code

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

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

Solution 2 :Change the function: render

Sometime,we need to change this function also.Here is the path of this function file.
> composer-view.js, File path: /wp-content/plugins/js_composer/assets/js/backend/composer-view.js:

Original function :

render: function () {
	var $shortcode_template_el = $( '#vc_shortcode-template-' + this.model.get( 'shortcode' ) );
	if ( $shortcode_template_el.is( 'script' ) ) {
		this.html2element( _.template( $shortcode_template_el.html(),
			this.model.toJSON(),
			vc.templateOptions.default ) );
	} 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
			},
			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;
	},

Change this function :

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

Note :
1: When changed then : Delete the cache and cookies : and then check.
2: If you are using the plugin : js_composer: or :WPBakery Visual Composer “: or :any paid plugin visual composer: then try to find the file : composer-view.js, File path: /wp-content/plugins/js_composer/assets/js/backend/composer-view.js: and changed the function which is discussed above.

Hope this works for you!

Tags:

Author information - Heycode Tech

Every world can ask question and my website registered user give the suggestion.

See all posts by Author

Connect to author

About us

Heycodetech is a platform where you can ask any questions related to the programming like PHP,jQuery, MYSQL,HTML , CSS and moreHere is the Expert group of programming.