Philippe Fisher
Philippe Fisher

Reputation: 596

Django CMS plugin

When writing a plugin the documentation states that you have to define a class that inherits from CMSPluginBase and you can pass info in the context. My question is what are the parameters that are passed in the render() function;

def render(self, context, instance, placeholder)

What is;

Upvotes: 1

Views: 165

Answers (1)

sthzg
sthzg

Reputation: 5554

For starters, the API documentation provides a few hints. Also the docs have more detailed information on components like placeholders and custom plugins.

instance
This is the current instance of your plugin. Imagine you have created a Django CMS plugin that renders testimonials on your website. It provides fields to upload a testimonial image, a name and the quote. You could have multiple instances of this plugin on each page, so the instance argument holds the currently rendered data.

So, if you have five instances of one plugin (e.g. the testimonials) on a page, render() will get called five times independently from one another and instance is the reference to the currently rendered entity.

placeholder
In your templates you can define multiple placeholders, like my_left_sidebar, the_footer, main_content, etc. Through the placeholder variable you can check in which placeholder the current instance is rendered.

Upvotes: 3

Related Questions