Skip to main content

Reusable Wagtail app to manage header and footer scripts sitewide and per-page.

Project description

Wagtail Header & Footer Scripts

A reusable Wagtail app for managing header and footer scripts across different sites using Wagtail Settings. It also supports adding page-specific header and footer scripts.

Features

  • Add header/footer scripts per site
  • Add header/footer scripts specific to individual pages
  • Use Wagtail settings and model clustering
  • Toggle scripts on/off
  • Render scripts using custom template tags
  • Supports easy integration into Wagtail pages via models

Installation

pip install wagtail-headers-footers

Add to INSTALLED_APPS

INSTALLED_APPS = [
    ...
    "wagtail.contrib.settings",
    "wagtail_headers_footers",
]

Add context processor to your settings

TEMPLATES = [
    {
        ...
        "OPTIONS": {
            "context_processors": [
                ...
                "wagtail.contrib.settings.context_processors.settings",
            ],
        },
    },
]

Migrate Wagtail H/F

python manage.py migrate wagtail_headers_footers

Usage

Add Site-wide scripts

Go to Settings > Headers & Footers in the Wagtail Admin to manage your scripts.

Wagtail Admin Screenshot

Add page-specific scripts

For page-specific headers and footers, you can add them by inheriting the following in your page models:

from wagtail.models import Page
from wagtail_headers_footers.models import PageHeaderFooterScriptsMixin

class HomePage(PageHeaderFooterScriptsMixin, Page):
    content_panels = Page.content_panels + PageHeaderFooterScriptsMixin.header_footer_panels

Don't forget to make migrations and migrate if neccessory.

Go to Pages in the Wagtail Admin to manage your page-specific scripts.

Wagtail Admin Page Screenshot

Add to your templates

Add the following code to your base template where you want to render the scripts:

{% load header_footer_tags %}

<head>
	...
    {% render_header_scripts %}
	...
</head>
<body>
    ...
    {% render_footer_scripts %}
	...
</body>

This will render both the site-wide and page-specific header/footer scripts dynamically.

Testing

python -m unittest discover tests

License

MIT

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_headers_footers-0.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

wagtail_headers_footers-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_headers_footers-0.1.1.tar.gz.

File metadata

File hashes

Hashes for wagtail_headers_footers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fe694060dd595472755108e245744d2f908e5f7f9d871370cfaa76df6e572fa5
MD5 238963c2ec8b9358f20d5c5f9c9d0c3b
BLAKE2b-256 76311c283813ab842f2716c4831fc382567862199dfd93743d547f55ff18e5d5

See more details on using hashes here.

File details

Details for the file wagtail_headers_footers-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_headers_footers-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2bf4eb48a20e49ea01b4e4adb1f7994eef9e0f9bfcf55082d35f6e9365948e0
MD5 f7c2a2d4547545ceec9fc0b596709ff6
BLAKE2b-256 275030802fe8e8450ad729f78b1384a2a99de82de0e3e180d2eeec89548b0149

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