You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vtiger CRM邮件模板选择时覆盖CKEditor已有内容问题求助

Vtiger CRM邮件模板选择时避免覆盖CKEditor已有内容的解决方案

你需要修改layouts\v7\modules\EmailTemplates\resources\Edit.js中模板内容加载的逻辑,添加CKEditor内容非空判断,具体步骤如下:

  1. 找到文件中负责加载模板内容的函数(通常是loadTemplateContent或类似命名的函数),或者找到模板下拉框(id一般是templatereference)的change事件回调。

  2. 在获取到模板内容准备赋值给CKEditor的位置,添加判断逻辑:

    • 先获取CKEditor实例及当前内容
    • 如果内容不为空,要么弹出确认框让用户选择是否覆盖,要么直接跳过赋值操作

示例代码(确认覆盖版):

function loadTemplateContent(templateId) {
    Vtiger_Connector.request({
        url: 'index.php?module=EmailTemplates&action=GetTemplateContent&record=' + templateId,
        success: function(response) {
            var editor = CKEDITOR.instances['emailtemplatecontent'];
            // 判断编辑器是否有内容
            if (editor && editor.getData().trim() !== '') {
                // 弹出确认框,用户取消则终止操作并重置模板选择
                if (!confirm('编辑器已有内容,确定要覆盖吗?')) {
                    document.getElementById('templatereference').value = '';
                    return;
                }
            }
            // 赋值模板内容
            editor.setData(response.content);
        }
    });
}

如果不想弹出确认,只在编辑器为空时加载模板,可替换为:

function loadTemplateContent(templateId) {
    Vtiger_Connector.request({
        url: 'index.php?module=EmailTemplates&action=GetTemplateContent&record=' + templateId,
        success: function(response) {
            var editor = CKEDITOR.instances['emailtemplatecontent'];
            if (editor && editor.getData().trim() === '') {
                editor.setData(response.content);
            } else {
                alert('编辑器已有内容,未加载所选模板');
                document.getElementById('templatereference').value = '';
            }
        }
    });
}
  1. 修改完成后,必须清除Vtiger的缓存:
    • 前端按Ctrl+F5强制刷新页面
    • 后台进入「设置」->「系统设置」->「缓存管理」,清除所有缓存

如果之前修改没生效,大概率是没找到正确的模板加载触发逻辑,或者缓存没清导致旧代码仍在运行。

内容的提问来源于stack exchange,提问作者Avril

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 10:12:34