Skip to main content

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

  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" %}
    
    {% 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

  1. Make sure you have Python virtual env installed
    $ python -m venv .venv
    
  2. Install this app in editable mode
    $ pip install -e .
    
  3. Migrate testapp DB
    $ python manage.py migrate
    
  4. Run the testapp
    $ python manage.py runserver
    
    Or hit F5 if you use Visual Studio Code

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

wagtail_crx_block_frontend_assets-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file wagtail_crx_block_frontend_assets-0.1.0.tar.gz.

File metadata

File hashes

Hashes for wagtail_crx_block_frontend_assets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 455cb5ef5dc5f4821db6a041c879979911a38a79682ebe0e592eb1f795024a19
MD5 097699b185aff37d231a6c9521364180
BLAKE2b-256 2bc1df689028618256eb86102fadbd9d5f334fd5a143c9f338d4e60251a7ff11

See more details on using hashes here.

File details

Details for the file wagtail_crx_block_frontend_assets-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_crx_block_frontend_assets-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d796c61aa614324ebe772ee0fdb86504f9100d6f11afc2020c53a5903f41aa4
MD5 e1b7e6d4ac3a50f189ba2e1173f6f826
BLAKE2b-256 d15dc8ede3ea684ef7ff936f9221bf5f80d783b3a2bd5cf353e68b1b3a757d20

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page