Configuration#
Restricting the Available Content Block Templates#
You can restrict the available content block templates by creating ContentBlockAvailability objects in the admin site. Create a new ContentBlockAvailability and choose the appropriate content_type. For example if you have an app called pages with a model called Page choose pages | page. Then choose the content block templates you want to make available.
This is useful to restrict the templates which can be used for a certain content type. For example you may have several apps serving several sections of your website. You can restrict which content block templates can be used on each section.
It is also useful when using NestedField as you may not want the content block templates associated with the NestedField to be available for use as a top level content block.
If you don’t provide a ContentBlockAvailability for any given content type then all content block templates will be available by default.
Content Block Previews#
Content block previews are shown via iframes. This is such that the content block can be rendered using your base template and shown in the content block editor without conflict.
This assumes you have a base template called base.html in the root of your project templates directory. And this template contains a {% block body %} just inside the <body> tag. It also assumes you will load all necessary static assets required to properly render the content block in the base template. See base.html in the repo example project for a minimal example.
If you do not have a base template or it does not define a {% block body %} you can override the template at content_blocks/content_block_preview.html to suit your needs. See the packaged content_block_preview.html for reference.
Page Previews#
To enable page previews in the content block editor you need to add a preview_url property to your parent model which returns a valid url to preview the page. You will also need to provide a view for this url. This view is responsible for providing content_blocks.previews() instead of content_blocks.visible(). For an example see the Example Pages App documentation.
Storage Backend Settings#
CONTENT_BLOCKS_STORAGEThe storage backend to use for
Image,VideoandFilefields. Provide a dotted path as per theSTORAGESsetting.Defaults to your
STORAGES["default"]["BACKEND"]setting.CONTENT_BLOCKS_IMAGE_STORAGEIf provided will override the storage backend used for images.
CONTENT_BLOCKS_FILE_STORAGEIf provided will override the storage backend used for files.
CONTENT_BLOCKS_VIDEO_STORAGEIf provided will override the storage backend used for videos.
Font Awesome Pro Support#
Django Content Blocks was made using Font Awesome 6 pro icons. However due to licencing it is not possible to include them in this package and Font Awesome free icons are used instead.
If you have an appropriate licence to use Fontawesome pro icons in your project you can enable them by providing the following files from your Font Awesome 6 pro kit in your project’s static directory.
content_blocks
└── fontawesome
├── css
| ├── fontawesome.min.css
| ├── light.min.css
| └── thin.min.css
└── webfonts
├── fa-light-300.ttf
├── fa-light-300.woff2
├── fa-thin-100.ttf
└── fa-thin-100.woff2
django-dbtemplates Support#
django-dbtemplates let’s you create and edit Django template files in the admin site. You can use this to edit content block html template files in the admin site, as well as any other template in your project.
If you set it so that the dbtemplates loader is used before the file loader dbtemplates will be used in preference to the files. This lets website administrators edit html templates without having any knowledge of Django.
If you are using dbtemplates a button is added to the ContentBlockTemplate admin change page which links to the dbtemplates change page where the html template can be edited.
django-cleanup Support#
Django Content Blocks removes unused media files via it’s own signals. If you are using django-cleanup you don’t need to do anything as all the relevant models are decorated with @cleanup_ignore to avoid conflicts.