Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual composer doesn't load and gives TypeError: _.template(...).trim is not a function

My visual composer plugin doesn't work. It stuck on the loading page. And it gives an error "TypeError: .template(...).trim is not a function" Error is on this line of code: this.$controls = $(.template(template, data, vc.template_options).trim()).addClass('vc_controls');

Please help me to fix this out.

Here is the error which I get:

screenshot

like image 522
Mohsin Awan Avatar asked Apr 14 '16 20:04

Mohsin Awan


People also ask

How to fix visual composer not working on WordPress?

Re-Save your page can fix Visual Composer issues First thing to try is top simply go to your page in the backend and re-save your page by clicking the “update” button. Then try the Visual Composer builder again and see if it’s working. 2. Make sure your theme and plugin is up to date

Why can’t I see all available Visual Composer modules?

Check your Settings If you aren’t seeing all the available Visual Composer Modules please go to Visual Composer > Role Manager and double check that they are all enabled for your specific admin roles. If you aren’t sure how to do that please view our Video Guide. 6. Front-End Editor Not Working?

Why is the front-end not working on the Visual Composer?

If your site and WordPress URL’s aren’t the same it can cause issues with the Front-End not working on the visual composer, so please make sure they are the same. You would check this at Settings / General. Why is this the case?

Why is Visual Composer not working in Plesk?

In the newer versions of Plesk there is a WordPress Toolkit which has some great options, however, if not setup correctly it could cause the Visual Composer from not working in the Front-End editor. So if you are using these functions, please double check to make sure they aren’t the cause of your problems. 9.


2 Answers

If you are unable to solve this error by upgrading or downgrading your theme or plugin, you could at least make the below changes.

1. Open the following two files:

wp-content\plugins\js_composer\assets\js\frontend_editor\frontend_editor.js
wp-content\plugins\js_composer\assets\js\frontend_editor\custom_views.js

2. Replace

this.$controls = $( _.template( template, data, vc.template_options ).trim() ).addClass( 'vc_controls' );

with

this.$controls = $( ( "vc.template_options" ).trim() ).addClass( 'vc_controls' );

This will surely work.

like image 109
maulik Avatar answered Oct 09 '22 20:10

maulik


Solution Goto file /wp-content/plugins/js_composer_salient/assets/js/dist/backend.min.js around line 4045:

======> Replace the code

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()
},
like image 33
Amritosh pandey Avatar answered Oct 09 '22 18:10

Amritosh pandey