reuse same django cms plugin instance

北战南征 提交于 2019-12-11 07:58:48

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/19801788/reuse-same-django-cms-plugin-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!