Wagtail CRX block frontend assets rendering
Define and organize frontend assets (like js or css files) for your Wagtail CRX blocks.
Supported versions
- See the badges above for tested versions.
- "Locked" and "floating" dependency sets are tested.
- Locked sets pin Django + Wagtail + CodeRed via
constraints/*.txt. - Floating sets pin Wagtail + CodeRed only, letting Django float within their ranges.
- To support a new version, add a constraint file in
constraints/and a matching tox/CI entry.
Getting started
-
Add the app to INSTALLED_APPS:
INSTALLED_APPS = [ ... "wagtail_crx_block_frontend_assets", ... ] -
Integrate your blocks with this app.
from wagtail.blocks import CharBlock, StructBlock from wagtail_crx_block_frontend_assets.blocks import BlockStaticAssetsRegistrationMixin class FrontendAssetsBlock(BlockStaticAssetsRegistrationMixin, StructBlock): title = CharBlock( required=False, label="Title", ) def register_assets(self, block_value): static_assets = [] static_assets += [ self.StaticAsset("path/to/asset.js", target="_blank"), self.StaticAsset("path/to/style.css", media="print"), ] return static_assetsYour block class has to inherit from
BlockStaticAssetsRegistrationMixinand you have to implementregister_assetsfunction. This function returns array ofBlockStaticAssetsRegistrationMixin.StaticAssetinstances. You can useblock_valueparameter to conditionally render assets based on current block values. -
Then you can define place in your templates where you want your block assets to be rendered like this:
{% extends "coderedcms/pages/base.html" %} {% load block_assets_tags %} {% block custom_assets %} {{ block.super }} {% render_block_assets required_file_extension=".css" %} {% endblock custom_assets %} {% block custom_scripts %} {{ block.super }} {% render_block_assets required_file_extension=".js" %} {% endblock custom_scripts %}
Development
- Make sure you have Python virtual env installed
$ python -m venv .venv - Install this app in editable mode
$ pip install -e . - Run tests (single environment)
$ pip install -e .[test] $ pytest - Run the compatibility matrix
$ tox - Migrate testapp DB
$ python manage.py migrate - Run the testapp
Or hit F5 if you use Visual Studio Code$ python manage.py runserver
Metadata
Release files for wagtail-crx-block-frontend-assets 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wagtail_crx_block_frontend_assets-1.2.0.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wagtail_crx_block_frontend_assets-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.1 kB
Release files / wagtail_crx_block_frontend_assets-1.2.0.tar.gz
| Download URL | wagtail_crx_block_frontend_assets-1.2.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
923dcc0d87c7205a8faa6de18c1b4c5ef57338197b127d5fd92809aafeaf71af
|
|
BLAKE2b-256 checksum How to use checksums |
1187ee936e442a1bddfc2f1d6f9691288fd2335e484f531183322665ce5635a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / wagtail_crx_block_frontend_assets-1.2.0-py3-none-any.whl
| Download URL | wagtail_crx_block_frontend_assets-1.2.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72bfeb035f89788626622f1fa9826021eed9d7b2f85888da2aec50f616e92aa6
|
|
BLAKE2b-256 checksum How to use checksums |
e5a9a69fc92481170ce2db5807b38227358cd5d28f127867fa4ad90c9d562940
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|