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是通过internet与客户机/服务器应用程序交互的最佳方式吗?   awt为什么不推荐java getPeer调用?   java类的添加方法   java在启动tomcat时传递数据库身份验证详细信息   如何创建具有关联值(如Swift enum)的Java枚举?   如何清理这个Java示例内存   visualvm如何在Java Visual VM中解释大型自时结果?   当实例变量的名称与参数变量相同时,java调用实例变量   eclipse缺少工件组织。硒。硒:seleniumjava:jar:3.14.59   java如何在Android Studio中Expandablelistview的子布局中使用Listview   从Guava 19升级到20时出现java编译错误   java在Maven 2中,我如何知道哪个依赖项来自于可传递依赖项?   需要javascript简单数据分级应用程序支持   接受特定对象或其子类型的java通用方法   在Java中剥离HTML   错误的Java字符串连接   Mybatis,Mysql中重复更新查询的java语法错误