【问题标题】:Django ckeditor with wordcount带有字数的 Django ckeditor
【发布时间】:2011-11-26 13:56:43
【问题描述】:

有人知道如何将此wordcount plugin 与现有的 django-ckeditor 应用程序集成吗? https://github.com/dwaiter/django-ckeditorhttps://github.com/shaunsephton/django-ckeditor/

具体来说,我被困在第 4 步

对于您的 CKEditor 实例,使用以下 HTML 标记(content 可以是您希望的任何元素名称,只要隐藏字段的元素名称格式为 elementWordCount

<label for="content">Content</label>
<textarea class="ckeditor" name="content"></textarea>
<input name="contentWordCount" type="hidden" value="250" />

我在哪里插入 Input 元素?

顺便说一句,我正在使用小部件。

欢迎使用 wordcount 插件的替代解决方案。

【问题讨论】:

    标签: django ckeditor ckeditor-wordcount


    【解决方案1】:

    我是https://github.com/shaunsephton/django-ckeditor/ 的作者。 我刚刚更新了 repo 以支持小部件模板自定义。

    您现在应该能够通过将 wordcount 插件指定为 CKEDITOR_CONFIGS 设置的一部分来集成它:

    CKEDITOR_CONFIGS = {
        'default': {
            'extraPlugins': 'wordcount',
        }
    }
    

    然后覆盖ckeditor/widget.html 模板,如下所示:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
    <input name="contentWordCount" type="hidden" value="250" />
    
    <textarea{{ final_attrs|safe }}>{{ value }}</textarea>
    <script type="text/javascript">
        CKEDITOR.replace("{{ id }}", {{ config|safe }});
    </script>
    

    我在这里通过 Google API 加载 jQuery 只是作为示例。

    【讨论】:

    • 甜蜜。会尝试并回复您!
    • 所以我已经包含了 wordcount 插件,我在右下角看到了 wordcount。但是当我更新ckeditor/widget.html 时,我无法在我的页面源上看到元素&lt;input name="contentWordCount" type="hidden" value="250" /&gt;。我是不是做错了什么?
    • 好吧,我想通了。我不得不将contentWordCount 中的content 更改为&lt;id attribute of text area field&gt;WordCount。将值更改为 nameclass 属性对我没有用。
    猜你喜欢
    • 2014-09-20
    • 2018-01-16
    • 2018-01-04
    • 2014-07-31
    • 2014-07-13
    • 1970-01-01
    • 2018-04-06
    • 2018-11-07
    • 2018-12-13
    相关资源
    最近更新 更多