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

前端 未结 11 1378
孤街浪徒
孤街浪徒 2021-02-05 11:07

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 co

相关标签:
11条回答
  • 2021-02-05 11:23

    I tried the following solutions:

    • maulik`s (but there was no such files on my plugin folder - frontend_editor.js and custom_views.js, just a "vendors" folder on "/wp-content/plugins/js_composer/assets/js/frontend_editor"),

    • Amritosh pandey`s solution (does not work even after cache & history cleaning),

    • Berein`s solution (does not work too).

    I solved the problem by using a Amritoshpandey's solution: https://gist.github.com/levantoan/519bb0d42c9f7bd6c4d78ef1686bb848 ("The following code has completely corrected my problems, I can load the page, add, clone, remove, etc")

    The Amritoshpandey's code should be pasted in /wp-content/plugins/js_composer/assets/js/dist/backend.min.js instead of:

    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,_vcnonce:window.vcAdminNonce},dataType:"html",context:this}).done(function(html){this.html2element(html)})}return this.model.view=this,this.$controls_buttons=this.$el.find(".vc_controls > :first"),this},

    0 讨论(0)
  • 2021-02-05 11:31

    This article suggests rolling back your worpress version prior to 4.5. http://forums.artbees.net/t/urgent-wordpress-4-5-broken-vc-backend-editor-workaround-fix-in-comments/2734

    This is where you can find older versions of wp to install https://wordpress.org/download/release-archive/30

    I haven't tried this myself just a suggestion.

    If this is still a problem for you I solved this same error I was getting by manually updating my theme through ftp. I downloaded the latest version of the theme because automatic updates were not working. I kept wordpress version 4.5. Here are the steps I took as follows.

    1. I renamed the theme example x-updating once uploaded named the current theme x-previous then changed x-updating to x and deleted x-previous.
    2. I updated js_composer the same way as step 1. Uploaded latest version of js_composer which was bundled with the theme. This is updated in plugins outside the theme. At this point you should be able to update visual composer from the wp dashboard if it hasn't already.
    3. This got vc working again but left me with some weird errors happening in vc_templates vc_column.php file. I had to manually comment out the trouble code to get the errors to go away.

    These 3 steps are a little nerve racking if you are not familiar with uploading files directly to your public_html root directory of your website. Some themes may offer support and do the ftp uploading for you if you provide them with ftp username password.

    One more thing to do is clear your cache for your website. In chrome you can clear your cache by going to chrome://settings/cookies enter website.com in the search bar and click remove all clearing all locally stored data for your website. Manual updating themes and plugins is recommended only if auto updates aren't possible then you do the above. For my theme and this same exact error in question I followed these really well-done steps https://community.theme.co/kb/updating-your-theme-and-plugins/. However this will be different depending which theme you have. And if you would rather roll back your wp version you can follow my original suggestion. But for me I like to have everything new and up-to-date.

    One more important note if you do have this theme then I had to delete x-shortcodes plugin from plugins direcotry of my website because my updated theme uses cornerstone instead of x-shortcodes to process important shortcodes to make vc work properly. Another thing to know is none of your data should be harmed while uploading plugins and themes all the data/content is stored safely in your data-base not in your theme.

    0 讨论(0)
  • 2021-02-05 11:31

    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()
    },
    
    0 讨论(0)
  • 2021-02-05 11:31

    You should try to fix this by up/downgrading your theme/plugin. But if you, like me, can't solve it this way and just need to do a quick hack to get past this particular problem, the following worked for me.

    Edit 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
    

    Change a single line in each of them, adding (). Change:

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

    to:

    this.$controls = $( _.template( template, data, vc.template_options )().trim() ).addClass( 'vc_controls' );
    
    0 讨论(0)
  • 2021-02-05 11:31

    1.Please Deactivate the plugin 2.Delete all the files from plugin folder (js_composer folder) 3.Download the Latest Version of Visual Composer 4.Add new Plugin --> and select the downloaded plugin -->Upload --->Activate

    0 讨论(0)
  • 2021-02-05 11:38

    If you have Visual Composer 4.9, just replace these 2 files from archive - frontend-editor.min.js - backend.min.js

    path: /wp-content/plugins/js_composer/assets/js/dist

    Don't forget to make a backup of your files.

    https://yadi.sk/d/JH4cbtnH3UoU3F

    click "download add" (tested with VC 4.9 & WP 4.9.5)

    0 讨论(0)
提交回复
热议问题