django-cms改进文本插件
项目描述
是django CMS的Text插件的增强版本。它允许CMS内容编辑器在模板中选择包装文本插件。
需求
Django 1.4+
Django CMS 2.3+
djangocms-text-ckeditor(如果使用cms 3+)
安装
将cmsplugin_text_ng添加到您的INSTALLED_APPS。
创建一些模板(更多内容将在之后介绍)并在管理中添加它们。
基本示例:静态模板
假设你想有一个带有Facebook“赞”按钮的文本插件。你的模板可能看起来像这样
<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 %}模板标签的作用
{% 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-text-ng自带一个类型(text)。此外,在cmsplugin_text_ng.contrib.textng_filer中有一个image类型,它使用django-filer向模板上下文添加图像。如果你想使用它,请确保filer和cmsplugin_text_ng.contrib.textng_filer都列在你的INSTALLED_APPS中。
真正的高级示例:定义自己的类型
因此,你想要在“赞”按钮下方添加一些HTML代码,并且内容编辑器坚持使用TinyMCE。让我们这么做!使用来自django-tinymce的出色HTMLField,我们设置了一个带有tinymce文本区域的模型
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)
需要注意几点
你的类型必须从TextNGVariableBase继承。
包含应最终出现在上下文中数据的字段必须命名为“value”
它必须是可空的(包含null=True部分)。
类型名称(在示例中为htmltext)在整个项目中必须是唯一的。你可能想用你应用程序的唯一前缀来修饰它。
如果这些条件不满足,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>
完成了。
项目详情
cmsplugin-text-ng-0.6.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 92cd33ba851bb9650effa187f4aa786004e2560730b6c3eb647fd2421daabd14 |
|
MD5 | dbd527f32973a49ff4b47134ae30f8f0 |
|
BLAKE2b-256 | b864a654c38a25610c586c564afb64230d87498e4bf4271d24a8a22e169f1b8b |