【发布时间】:2015-03-16 07:01:36
【问题描述】:
我尝试在自定义 cms 插件中呈现占位符。由于某种原因,我可以看到在 DOM 中创建了占位符标记,但是当我切换到编辑模式时,我在任何地方都看不到占位符。我无法在该占位符中创建任何插件。
代码如下:
models.py
class TabItem(CMSPlugin):
tab_name = models.CharField(max_length=8)
place_holder = PlaceholderField("place_holder_name")
cms_plugins.py
class TabItemPlugin(CMSPluginBase):
module = _("c2ms_module_information_tab")
model = TabItem
name = _("Tab Item")
render_template = "c2ms_module_information_tab/tab.html"
allow_children = True
def render(self, context, instance, placeholder):
context.update({
'instance': instance,
'placeholder': placeholder,
})
return context
模板:
{% load cms_tags staticfiles sekizai_tags placeholder_tags %}
<a href="#">{{ instance.tab_name|safe }}</a>
<div class="expanded">
{% render_placeholder instance.place_holder "640" %}
</div>
【问题讨论】:
-
我从来没有尝试过自己在插件中渲染占位符,这背后的想法是什么?我目前无法对此进行测试。我很想在项目的 github 上提出问题。 github.com/divio/django-cms/issues
-
@marksweb 这是我在尝试渲染占位符时看到的内容django-cms.readthedocs.org/en/develop/how_to/placeholders.html
标签: python django django-cms