Search code examples
pythondjangodjango-cms

Django CMS simple placeholders outside of cms


I have a fully developed Django app and decided to add DjangoCMS to give a content developers a quick way to prototype landing pages etc. It now lives under myurl.com/cms and works quite well. The guys can create new pages, choose a template and add plugins there.

When i saw the placeholder template tag I immediately thought about placing it all over the project, outside the cms, everywhere I want the product team to be able to quickly add and change content. I don't want them to create a new page for this from the cms because maybe the site has complex functionality which is only used once in this context (i.e. the search page).

So basically I expect to have static placeholders that I can place in the html part of the page using the cms plugins template tags.

I already found Placeholders outside the CMS in the DjangoCMS docs. But for this to work I have to grab the related placeholder object for every view that renders a page, which would increase the amount of work to "quickly add a placeholder for this text" considerably.

Is there an easy way to do this? I kind of expect to not be the first to have that issue.


Solution

  • There's three types of placeholders:

    Page placeholders - Declared using {% placeholder %}. These can only be used inside a cms page.

    Static placeholders - Declared using {% static_placeholder %}. Not bound to pages or objects.

    App placeholder - Declared in your models.py using PlaceholderField and rendered in template using {% render_placeholder %}

    The rule of thumb is, if you're rendering a cms page, use a page placeholder, otherwise depending on your use-case use a static placeholder.