在不同的splaceholder /模板上渲染Django-CMS插件不同 [英] Render Django-CMS plugins differently on different splaceholders/templates

查看:240
本文介绍了在不同的splaceholder /模板上渲染Django-CMS插件不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本:我想使用相同类型的cmsplugin在不同的占位符中使用不同的模板。这可能吗?或者,我应该去做自定义插件吗?

Short version: I'd like to have the same kind of cmsplugin use different templates in different placeholders. Is this possible? Or, should I go and make my custom plugin?

长版本:使用Django和Django-CMS并使用 cmsplugin-video-youtube 插件,我在主页上有两个YouTube视频,他们的风格是使用基金会4的网格系统堆叠在一个然后另一个下面,并在浏览器的宽度的某个断点,他们将并排。这一切都很好。

Long version: Using Django and Django-CMS and using the cmsplugin-video-youtube plugin, I have two youtube videos on the home page and they are styled using Foundation 4's grid system to be stacked one and then another below it and at a certain 'breaking point' of the browser's width, they will be side-by-side. This is all working well.

现在我想在不同的占位符中添加一些无限数量的YouTube视频在不同的页面,它是一个不同的模板。而且我想让他们在一个下面放置一个,等等,并且在浏览器宽度的某个断点上,它们将是水平的并排对,一对低于前者,等等。

Now I'd like to add some unlimited number of YouTube videos in a different placeholder that is in a different page, which is of a different template. And I would like to have them rendered one below the former and so on and on a certain 'breaking point' of the browser width they will be horizontal side-by-side pairs, one pair below the former and so on.

由于这些YouTube视频元素是无限制的,而不是预定义的数字,我无法使用网格系统。我想我会使用阻止网格系统。这使我在< u> 元素中创建元素< li> 元素。这要求我更改 cmsplugin-video-youtube 元素的模板,以便呈现这些< li> 元素YouTubes。这个问题是,如果我重写此插件的模板,通过提供 templates / cmsplugin-video-youtube / embed.html ,它也将覆盖它并更改它对于主页中的这个插件的实例。而我喜欢他们,因为他们是。

Since these YouTube video elements are of an unlimited, not predefined, number, I can't use the grid system. I figured I'd use the block grid system. This has me create the elements as <li> elements inside a <u> element. This requires that I change the template for the cmsplugin-video-youtube element to render those <li> elements around the YouTubes. The problem with this is that if I override the template for this plugin, by supplying templates/cmsplugin-video-youtube/embed.html, it will also override it and alter it for the instances of this plugin that are in the home page. And I like them as they are.

所以我认为,有一种方法可以覆盖一个插件的模板只有一个特定的占位符。这将允许我在另一个页面的特定占位符中指定YouTube的呈现,而不影响我的主页中的这个插件的实例。

So what I thought is that it would be beneficial to have a way of overriding the template for a plugin only for a specific placeholder. That would allow me to specify the YouTube's rendering in a specific placeholder in my other page and not affect the instances of this plugin in my home page, which I like as they are.

有没有这样的选择 - 覆盖特定占位符的插件模板?

Is there such an option - to override the template of a plugin for a specific placeholder?

否则,我认为这可能需要一个基于现有的 cmsplugin-video-youtube 的自定义插件,也许是一个子类我会假设,那么这个模板就需要与< li> 元素在这个其他页面上。

Otherwise, I thought that this might require a custom plugin that is based on the existing cmsplugin-video-youtube, perhaps a subclass of it, I would assume, that would then have the template that I require, with the <li> elements, for this other page.

不同的方法是尝试迭代插件实例的实例,并将它们整个< ul>< li> 他们周围的事情,一个接一个。我已经询问过,关于这种方法,根据我得到的一些答案,这似乎不是最简单的路线。

A different approach would be to attempt to iterate over the instances of the plugin instance and render them with the whole <ul><li> thing around them, one by one. I've inquired about this approach and according to some answers I got, it would seem to be not the most easiest route.

请问你的方法是什么?

我还没有收到答案。请,甚至一个指针会是一些东西!

I've not received an answer yet. Please, even a pointer would be something!

推荐答案

我知道这个问题很旧。但是希望有同样问题的人会发现这很有用。

I know this question is very old. .but hopefully anyone with same problem will find this useful.

查看CMSPluginBase的源代码:

Looking at sourcecode for CMSPluginBase:

https://github.com/divio/django-cms/blob/develop/cms/plugin_base.py

context['placeholder'] = placeholder

占位符在render方法中作为上下文传递。

Placeholder is passed as context in the render method.

所以在模板中,您可以使用它来呈现不同的输出。一个很好的例子:

So in the template you can use that to to render different output. A good example for this:

https://github.com/stefanfoulis/cmsplugin-filer/blob/develop/cmsplugin_filer_image/templates/cmsplugin_filer_image/plugins/image/default.html

这篇关于在不同的splaceholder /模板上渲染Django-CMS插件不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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