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_assets
Your block class has to inherit from
BlockStaticAssetsRegistrationMixin
and you have to implementregister_assets
function. This function returns array ofBlockStaticAssetsRegistrationMixin.StaticAsset
instances. You can useblock_value
parameter 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" %} {% block custom_assets %} {{ block.super }} {% include "wagtail_crx_block_frontend_assets/includes/block_assets.html" with required_file_extension=".css" %} {% endblock custom_assets %} {% block custom_scripts %} {{ block.super }} {% include "wagtail_crx_block_frontend_assets/includes/block_assets.html" with 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
File details
Details for the file wagtail_crx_block_frontend_assets-0.0.4.tar.gz
.
File metadata
- Download URL: wagtail_crx_block_frontend_assets-0.0.4.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2f122b7a7f24cd2fa95e135d323badacdb54522e4351e934be6d7b48258f58b |
|
MD5 | b8e5b21afa5c819c045547333aae1215 |
|
BLAKE2b-256 | 4459d1c9d1f6e1d0361c05c04ab4cd431dacfa119a4e016d4d06f1f45dd45721 |
File details
Details for the file wagtail_crx_block_frontend_assets-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: wagtail_crx_block_frontend_assets-0.0.4-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f7bd1c787210fe53dd62a3867cc0ae787d5bf62cd09d45e40cf8b6d0f0b14f |
|
MD5 | 3cd7d8ea5fd0fdc585e398651c5069b7 |
|
BLAKE2b-256 | 532ad67d6ab12e70c05fb6c4bc2dea2fef54f6ef36733c7e08f7c71faeb7b322 |