This package allows you to define and organise static assets for your Wagtail blocks frontend.
Project description
Wagtail CRX block frontend assets rendering
Define and organize frontend assets (like js or css files) for your Wagtail CRX blocks.
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 . - Migrate testapp DB
$ python manage.py migrate - Run the testapp
Or hit F5 if you use Visual Studio Code$ python manage.py runserver
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wagtail_crx_block_frontend_assets-1.0.0.tar.gz.
File metadata
- Download URL: wagtail_crx_block_frontend_assets-1.0.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca04d592ae399ae1b4f81e2e11dd9ae98a65ca9a9575833e1ec53f46599dc0f
|
|
| MD5 |
5558884217450ebdd43df5135ebad94d
|
|
| BLAKE2b-256 |
2dd329f45fe7478a73bb3c81cd87e42a095e16dfcbc26c94fc0cbedbea312873
|
File details
Details for the file wagtail_crx_block_frontend_assets-1.0.0-py3-none-any.whl.
File metadata
- Download URL: wagtail_crx_block_frontend_assets-1.0.0-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5863e00ceeb56ec5bcf223a40b5aab3547a82035a86b3f811530ae60b9263c55
|
|
| MD5 |
724a28d248b729b26951d7dd09670d90
|
|
| BLAKE2b-256 |
9d5e44aea5fe1933457120bd1ca4e0401f169a69d7c3ec0d31ea3e99222ff7b1
|