重用相同的django cms插件实例 [英] reuse same django cms plugin instance

查看:132
本文介绍了重用相同的django cms插件实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经在django cms中创建了一个像Box的插件,它允许用户放置页面URL和其他配置来显示Facebook的框。



现在用户想要显示多个页面相同的样箱,是否有可能重复使用相同的插件实例,而不在每个页面上创建的插件?

  class FacebookLikeBox(CMSPlugin):
page_url = models.URLField()
app_id = models.CharField(max_length = 25)
width = models.CharField(max_length = 25 )
height = models.CharField(max_length = 25)
color_scheme = models.CharField(max_length = 25,choices =(('light','light'),('dark' ))
show_friends_faces = models.BooleanField(default = True)
show_posts = models.BooleanField(default = True)
show_header = models.BooleanField(default = True)
show_border = models.BooleanField(缺省值=真)


解决。案

您有两种选择(也许更多)



如果您正在使用Django-CMS<然后,您可以安装 djangocms-stacks ,这是一个很酷的应用程序,允许您创建可重用的可以从管理就像一个占位符来管理插件的栈。



在堆栈将呈现它的所有插件,每当遇到 {%stackyourstackname%} 在模板中。



在django-cms> = 3.x中,这个包被移动到cms芯所以无需安装它。



第二个选择是使用 {%show_placeholder%} 模板标记。您可以阅读有关此标签的更多信息这里


Lets say I have created a facebook like box plugin in django cms, it allows the user to put in page urls and other configuration to display the facebook like box.

Now the user wants to display the same like box across multiple pages, is it possible to reuse the same plugin instance without creating the plugins on every page?

class FacebookLikeBox(CMSPlugin):
    page_url = models.URLField()
    app_id = models.CharField(max_length=25)
    width = models.CharField(max_length=25)
    height = models.CharField(max_length=25)
    color_scheme = models.CharField(max_length=25, choices=(('light','light'),('dark','dark')))
    show_friends_faces = models.BooleanField(default=True)
    show_posts = models.BooleanField(default=True)
    show_header = models.BooleanField(default=True)
    show_border = models.BooleanField(default=True)

解决方案

You have two options (maybe more).

If you are using django-cms < 3.x then you can install djangocms-stacks which is a cool application that allows you to create reusable "stacks" of plugins that can be managed from the admin just like a placeholder.

The the stack will render all it's plugin whenever it encounters the {% stack "yourstackname" %} in a template.

In django-cms >= 3.x this package was moved to the cms core so no need to install it.

The second option is using the {% show_placeholder %} template tag. You can read more about this tag here.

这篇关于重用相同的django cms插件实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆