Javascript Visual composer 不加载并给出 TypeError: _.template(...).trim is not a function

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36633822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:20:11  来源:igfitidea点击:

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

javascriptwordpress

提问by Mohsin Awan

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');

我的视觉作曲家插件不起作用。它卡在加载页面上。它给出了一个错误“TypeError: .template(...).trim is not a function”错误在这行代码上: 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

截屏

采纳答案by Ian Poston Framer

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

本文建议回滚 4.5 之前的 worpress 版本。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

在这里您可以找到旧版本的 wp 来安装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.

如果这对您来说仍然是一个问题,我通过 ftp 手动更新我的主题解决了同样的错误。我下载了最新版本的主题,因为自动更新不起作用。我保留了 wordpress 4.5 版。以下是我采取的步骤如下。

  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.
  1. 我在上传后将主题示例 x-updating 重命名为当前主题 x-previous 然后将 x-updating 更改为 x 并删除 x-previous。
  2. 我以与步骤 1 相同的方式更新了 js_composer。上传了与主题捆绑在一起的最新版本的 js_composer。这是在主题之外的插件中更新的。此时,您应该能够从 wp 仪表板更新视觉作曲家(如果还没有的话)。
  3. 这让 vc 再次工作,但让我在 vc_templates vc_column.php 文件中发生了一些奇怪的错误。我不得不手动注释掉故障代码以使错误消失。

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.

如果您不熟悉将文件直接上传到您网站的 public_html 根目录,那么这 3 个步骤会有点伤脑筋。如果您向它们提供 ftp 用户名密码,某些主题可能会提供支持并为您进行 ftp 上传。

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.

要做的另一件事是清除您网站的缓存。在 chrome 中,您可以通过转到 chrome://settings/cookies 在搜索栏中输入 website.com 并单击删除所有清除您网站的所有本地存储数据来清除缓存。仅当无法自动更新时才建议手动更新主题和插件,然后执行上述操作。对于我的主题和同样的问题,我遵循了这些非常好的步骤https://community.theme.co/kb/updating-your-theme-and-plugins/。但是,这会有所不同,具体取决于您拥有的主题。如果你更愿意回滚你的 wp 版本,你可以按照我原来的建议。但对我来说,我喜欢一切都是新的和最新的。

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.

一个更重要的注意事项,如果你有这个主题,那么我不得不从我网站的插件目录中删除 x-shortcodes 插件,因为我更新的主题使用基石而不是 x-shortcodes 来处理重要的短代码,以使 vc 正常工作。另一件要知道的事情是,在上传插件和主题时,您的任何数据都不应该受到损害,所有数据/内容都安全地存储在您的数据库中,而不是您的主题中。

回答by maulik

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:

1.打开以下两个文件:

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' );

2.替换
this.$controls = $( _.template( template, data, vc.template_options ).trim() ).addClass( 'vc_controls' ); 使用
this.$controls = $( ( "vc.template_options" ).trim() ).addClass( 'vc_controls' );

This will surely work.

这肯定会奏效。

回答by Amritosh pandey

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

解决方案转到文件 /wp-content/plugins/js_composer_salient/assets/js/dist/backend.min.js 周围 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()
},

回答by Natacha Beaugeais

Upgrade to Visual Composer version 4.11.2+

升级到 Visual Composer 版本 4.11.2+

Note Wordpress 4.5 compatibility was fixed on 13th April: https://wpbakery.atlassian.net/wiki/display/VC/Release+Notes

注意 Wordpress 4.5 兼容性已于 4 月 13 日修复:https: //wpbakery.atlassian.net/wiki/display/VC/Release+Notes

回答by Berein

As Shady sherif said at Maulik's suggestion, this is what I've changed in 2 places at frontend-editor.min.js and it worked!! Thanks to you both!

正如 Shady sherif 在 Maulik 的建议中所说的那样,这就是我在 frontend-editor.min.js 中的两个地方进行了更改,并且奏效了!!谢谢你们!

Change this:

改变这个:

this.$controls=$(_.template(template,data,_.extend({},vc.template_options,{ evaluate:/\{#([\s\S]+?)#}/g})).trim()).addClass("vc_controls");  

With this:

有了这个:

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

回答by PauloBoaventura

UPDATE: in current updates none of this is needed just replace the plugin

更新:在当前更新中,这些都不需要,只需更换插件











I had problem with WPBakery Page Builder in version 6.0.2.
Wordpress: Version 5.2.1

我在 6.0.2 版中遇到了 WPBakery Page Builder 的问题。
WordPress:版本 5.2.1

ERROR: Uncaught TypeError: window.vc.frame_window.jQuery is not a function at window.vc.ShortcodesBuilder.buildFromContent (frontend-editor.min.js? Ver = 6.0.2: 10)
???? at Object.vc.build (frontend-editor.min.js? ver = 6.0.2: 10)
???? at frontend-editor.min.js? ver = 6.0.2: 10

I was reluctant to upgrade, as there might be a bug. (But it is a fact that an update is bug fix)

我不愿意升级,因为可能存在错误。(但事实是更新是错误修复)

Since the update to version 6.0.3 was not successful.

由于更新到版本 6.0.3 没有成功。

Solution:

解决方案:

Mine was restoring the backup of the whole site.

我的正在恢复整个站点的备份。

Tip: Never forget Backup.

提示:永远不要忘记备份。

回答by Andrews32

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).

  • maulik`s(但我的插件文件夹中没有这样的文件 - frontend_editor.js 和 custom_views.js,只是“/wp-content/plugins/js_composer/assets/js/frontend_editor”上的“vendors”文件夹),

  • Amritosh pandey 的解决方案(即使在缓存和历史清理后也不起作用),

  • Berein 的解决方案(也不起作用)。

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")

我通过使用 Amritoshpandey 的解决方案解决了这个问题:https://gist.github.com/levantoan/519bb0d42c9f7bd6c4d78ef1686bb848 (“以下代码完全纠正了我的问题,我可以加载页面,添加,克隆,删除等”)

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

Amritoshpandey 的代码应该粘贴在 /wp-content/plugins/js_composer/assets/js/dist/backend.min.js 而不是:

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

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

回答by Alex Paray

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

如果您有Visual Composer 4.9,只需从存档替换这 2 个文件 - frontend-editor.min.js - backend.min.js

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

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

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

不要忘记备份您的文件。

https://yadi.sk/d/JH4cbtnH3UoU3F

https://yadi.sk/d/JH4cbtnH3UoU3F

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

单击“下载添加”(使用 VC 4.9 和 WP 4.9.5 测试)

回答by Captain Normal

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' );

回答by Anand

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

1.请停用插件 2.删除插件文件夹(js_composer 文件夹)中的所有文件 3.下载最新版本的 Visual Composer 4.添加新插件 --> 并选择下载的插件 --> 上传 ---> 激活