0
votes

I'm trying to implement the documentation on django-cms on How to use placeholders outside the CMS

It seems possible to define a field in a model app external to the CMS which will behave like the djangocms-text-ckeditor

But I can't get this 'templatetag' to work

{% extends 'base.html' %}
{% load cms_tags %}

{% block content %}
    <h1>Title page info</h1>
    {% render_placeholder object.short_text "640" %}
{% endblock content %}

Here my info.models.py

from django.db import models
from cms.models.fields import PlaceholderField

class MsgDet(models.Model):
    title = models.CharField(max_length=255)
    short_text = PlaceholderField('content')

I've create a small django-cms project following the django-cms tutorail using django CMS installer. The source code is on GitHub under OpenHBP/PlaceholderField. I've added a simple info app to the cms and I try to display "MsgDet.short_text" fields inside a "CKEditor like" plugin.

A double-click on the CMS home page opens a CKeditor window. I would like to achieve the same result on my info page!

I know this can be achieved by using RichTextField from ckeditor but I would like to use "PlaceHolderFiled" in order to have access to djangoCMS plugins: picture/image or file.

Note that I've also tried with django-ckeditor-filebrowser-filer but the project seems deprecated and pdf upload does not work.

I just want to be able to access filer files (images & documents) from a "CKEditor like" window...

1

1 Answers

0
votes

It works now!

I've added a CMS_PLACEHOLDER_CONF dict in settings.py with a specific "msgdet_slot" which contains default text 'Lorem ipsum dolor sit amet...' so that it is visible on the page WHEN connected to the CMS and WHEN the page is with status modified: ?edit at the end of the URL.

CMS_PLACEHOLDER_CONF = {
    None: {
        "plugins": ['TextPlugin'],
        'excluded_plugins': ['InheritPlugin'],
    },
    'msgdet_slot': {
        'plugins': ['TextPlugin', 'PicturePlugin', 'FilePlugin'],
        'text_only_plugins': ['LinkPlugin'],
        'extra_context': {"width":640},
        'name': "My slot",
        'language_fallback': True,
        'default_plugins': [
            {
                'plugin_type': 'TextPlugin',
                'values': {
                    'body':'<p>Lorem ipsum dolor sit amet...</p>',
                },
            },
        ],
        'child_classes': {
            'TextPlugin': ['PicturePlugin', 'FilePlugin'],
        },
        'parent_classes': {
            'LinkPlugin': ['TextPlugin'],
        },
    },
}

models.py has to be modified consequently

from django.db import models
from cms.models.fields import PlaceholderField

class MsgDet(models.Model):
    title = models.CharField(max_length=255)
    short_text = PlaceholderField('msgdet_slot')

Better to use your own slot instead of the generic 'content' used by the CMS so that you can modify the CMS plugins you want to be displayed. In my example I just display Picture and File Plugin.

Note also that if some pages have been edited with a slot called "myslot" and that you change it to "msgdet_slot", the configuration (visible CMS plugins) of the old pages will remain with "myslot". File PlaceHolder are indeed stored with unique PK in "cms_placeholder" table.