Skip to main content

Wagtail CRX block frontend assets rendering

PyPI version Python versions Django tested Wagtail tested CodeRed CMS tested License

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

  1. Add the app to INSTALLED_APPS:

    INSTALLED_APPS = [
     ...
     "wagtail_crx_block_frontend_assets",
     ...
     ]
    
  2. 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 implement register_assets function. This function returns array of BlockStaticAssetsRegistrationMixin.StaticAsset instances. You can use block_value parameter to conditionally render assets based on current block values.

  3. 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

  1. Make sure you have Python virtual env installed
    $ python -m venv .venv
    
  2. Install this app in editable mode
    $ pip install -e .
    
  3. Run tests (single environment)
    $ pip install -e .[test]
    $ pytest
    
  4. Run the compatibility matrix
    $ tox
    
  5. Migrate testapp DB
    $ python manage.py migrate
    
  6. Run the testapp
    $ python manage.py runserver
    
    Or hit F5 if you use Visual Studio Code

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)

Source distribution for wagtail-crx-block-frontend-assets 1.2.0
File Size Uploaded
wagtail_crx_block_frontend_assets-1.2.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-crx-block-frontend-assets 1.2.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page