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第三方库


热门话题
JavaFX进度条从单独的函数更改而来   jvm使用java服务器选项   java在<li>元素中查找同名的最后一个链接   java问题将参数传递给不同公共类中的构造函数   如何在php中从java函数中获取字符串   java如何在Android中动态显示多个tile   java仅使用Ribbon而不使用任何服务注册表是否可以实现负载平衡?   Jersey 1.19版本的java Swagger JAXRS出现“冲突URI模板”错误   带H2数据库的java Spring boot jpa   从12:00:00到00:00:00的日期转换   Android中的java如何设置文本?   java密钥库“不支持的保护参数”   http使用Java在Java中发送httprequest。净包   SpringJava刷新数据库   java在Spring Boot应用程序中使用嵌入式MongoDb和MongoTemplate失败   java需要什么MatOfMatch对象?   xml使用Java中的合并算法将两个值合并为单个值   java SQLite数据库不保存数据为什么不工作