Django CMS改进文本插件

cmsplugin-text-ng的Python项目详细描述


django CMSText插件的增强版本。它允许包装 可由CMS内容编辑器选择的模板内的文本插件。

注意

此插件不是用来替换cms.plugins.text。它是一个 对某些用例的增强。对于大多数类型的内容,您应该 可能仍然使用cms.plugins.text或编写专门定制的 插件。

要求

  • Django 1.4+
  • Django CMS 2.3+
  • djangocms text ckeditor(仅当使用cms 3+)

安装

  • Add ^{tt4}$ to your ^{tt5}$.
  • Create some templates (more on that soon) and add them in the admin.

基本示例:静态模板

假设你想要一个带有facebook“like”按钮的文本插件。你的 模板可能如下所示:

<div class="text left">
    {{ body|safe }}
</div>
<div class="fb-like right">
    <h2>Like this page on facebook!</h2>
    <fb:like send="false" width="450" show_faces="true"></fb:like>
</div>

高级示例:动态模板

假设您想在每个插件上设置<h2>-标记的内容 基础。没问题!这就是{% define %}template标记的作用:

{% load text_ng_tags %}
{% define h2_content as text %}
<div class="text left">
    {{ body|safe }}
</div>
<div class="fb-like right">
    <h2>{{ h2_content }}</h2>
    <fb:like send="false" width="450" show_faces="true"></fb:like>
</div>

当你编辑这个插件时,你会有一个文本框,上面写着“h2_content” 标签。其内容将在呈现插件时添加到上下文中。你 可以像任何上下文变量一样访问它:{{ h2_content }}

模板标记的as text部分引用变量的类型。 cmsplugin文本ng带有一个类型(text)。此外,还有一个 image键入使用 django-filer将图像添加到模板上下文。如果你想用它, 确保filercmsplugin_text_ng.contrib.textng_file都是 列在您的INSTALLED_APPS中。

真的(开玩笑)高级示例:定义自己的类型

所以,您需要在“like”按钮下面添加一些html代码,然后 内容编辑坚持使用tinymce。我们来吧!使用令人敬畏的 HTMLFielddjango-tinymce中,我们建立了一个带有tinymce'd的模型 文本区域:

from django.utils.translation import ugettext_lazy as _

from tinymce.models import HTMLField

from cmsplugin_text_ng.models import TextNGVariableBase
from cmsplugin_text_ng.type_registry import register_type

class TextNGVariableHTML(TextNGVariableBase):
    value = HTMLField(null=True, verbose_name=_('value'))

    class Meta:
        verbose_name = _('html text')
        verbose_name_plural = _('html texts')

register_type('htmltext', TextNGVariableHTML)

有几点需要注意:

  • your type has to inherit from ^{tt17}$.
  • the field containing the data that should end up in the context has to be named “value”
  • it has to be nullable (the ^{tt18}$ part).
  • the type name (^{tt19}$ in the example) has to be unique over the whole project. You might want to prefix it with something unique to your app.

cmsplugin text ng将抱怨(大声!)如果不满足这些条件。

我们在哪里?对,模板。在模板中使用你新的,很棒的类型, 只要使用{% define %}标记就可以了,就像这样:

{% load text_ng_tags %}
{% define h2_content as text %}
{% define html_content as htmltext %}
<div class="text left">
    {{ body|safe }}
</div>
<div class="fb-like right">
    <h2>{{ h2_content }}</h2>
    <fb:like send="false" width="450" show_faces="true"></fb:like>
    {{ html_content|safe }}
</div>

完成。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用URLhttp://localhost:8080/appcontext/METAINF/index.html?   Google应用程序引擎Java错误   java此GUI在设置BoxLayout后不显示任何内容   setParameter情况下的java临时类型(字符串名称、对象值)   Rijndael 256加密与Java&Bouncy Castle   java如何检查字符串是否为空?   java InvalidDataAccessResourceUsageException:无法提取结果集   AWTGLCanvas正在隐藏java JToggleButton工具提示   使用PDFBox的java格式数字   java Datainputstream和readUTF数据丢失   在java中使用axiomapi解码XJWT断言   为什么Java和PHP的相同代码不起作用?   JavaGoogleSigin错误,代码工作真实设备工作良好,但不工作模拟器获得错误ApiException 12500,谢谢,我也是新的   java通过使用JNA将void**参数作为char[]获取函数的结果   java如何使用泛型树集创建比较器?   未正确解析java简单文本文件   在java中将字符串转换为MyString对象类型   java Spring继承不起作用