Skip to main content

Adds snippet plugin to django CMS.

Project description

pypi coverage python django djangocms djangocms4

django CMS Snippet provides a plugin for django CMS to inject HTML, CSS or JavaScript snippets into your website.

This project is endorsed by the django CMS Association. Join us on Slack.

Warning: We recommend using this plugin only during development:

This plugin is a potential security hazard, since it allows authorized-
users to place custom markup or Javascript on pages bypassing all of
Django's normal sanitization mechanisms. This could be exploited by users
with the right to add snippets to elevate their privileges to superusers.
This plugin should only be used during the initial development phase for
rapid prototyping and testing.
preview.gif

Contribute to this project and win rewards

Because this is a an open-source project, we welcome everyone to get involved in the project and receive a reward for their contribution. Become part of a fantastic community and help us make django CMS the best CMS in the world.

We’ll be delighted to receive your feedback in the form of issues and pull requests. Before submitting your pull request, please review our contribution guidelines.

We’re grateful to all contributors who have helped create and maintain this package. Contributors are listed at the contributors section.

One of the easiest contributions you can make is helping to translate this addon on Transifex.

Documentation

See REQUIREMENTS in the setup.py file for additional dependencies.

Installation

For a manual install:

  • run pip install djangocms-snippet

  • add djangocms_snippet to your INSTALLED_APPS

  • run python manage.py migrate djangocms_snippet

Djangocms-snippet uses the ace code editor which normally is loaded from a CDN. If you prefer your application to provide the editor locally, you can change the requirement from djangocms_snippet to djangocms_snippet[static-ace] and add djangocms_static_ace to your project’s INSTALLED_APPS.

Configuration

To allow the contents of all snippets to be searchable, please set DJANGOCMS_SNIPPET_SEARCH to True in your settings:

DJANGOCMS_SNIPPET_SEARCH = True

We are using Ace as our editor of choice to edit the snippet content. You can customize the theme and mode through:

DJANGOCMS_SNIPPET_THEME = 'github'
DJANGOCMS_SNIPPET_MODE = 'html'

If dynamic content is inserted (for example {% show_menu ... %}), the plugin cache must be disabled, please set DJANGOCMS_SNIPPET_CACHE to False in your settings:

DJANGOCMS_SNIPPET_CACHE = False # default value is False

Migration 0010 requires the use of a user in order to create versions for existing snippets (if djangocms_versioning is installed and enabled), a user can be chosen with the setting DJANGOCMS_SNIPPET_VERSIONING_MIGRATION_USER_ID, the default is 1. This setting is also exposed as an Environment variable for Divio projects using the Divio addon.

DJANGOCMS_SNIPPET_VERSIONING_MIGRATION_USER_ID = 2 # Will use user with id: 2

Template tag

You can also use a template tag to render a snippet rather than a plugin:

{% load snippet_tags %}
{% snippet_fragment [reference] %}

Replace [reference] with either:

  • The snippet ID, e.g. {% snippet_fragment 42 %}

  • The snippet slug, e.g. {% snippet_fragment 'my-snippet' %}

  • The snippet instance, e.g. {% snippet_fragment instance.snippet %}

Optionally provide a fallback if there is no matching id/slug/instance:

{% snippet_fragment 'my-snippet' or %}
    ... your content fallback here ...
{% endsnippet_fragment %}

Running Tests

You can run tests by executing:

virtualenv env
source env/bin/activate
pip install -r tests/requirements.txt
python setup.py test

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

djangocms_snippet-5.0.0.tar.gz (42.2 kB view details)

Uploaded Source

Built Distribution

djangocms_snippet-5.0.0-py3-none-any.whl (150.4 kB view details)

Uploaded Python 3

File details

Details for the file djangocms_snippet-5.0.0.tar.gz.

File metadata

  • Download URL: djangocms_snippet-5.0.0.tar.gz
  • Upload date:
  • Size: 42.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for djangocms_snippet-5.0.0.tar.gz
Algorithm Hash digest
SHA256 05d0882bd549b6be6fe0050ad0c0d7a2abf0847ba0cc150100a5f420e5fd3abf
MD5 d7c3ee88bbc7cc569b47ac06d929eea0
BLAKE2b-256 1d948d060ae2d3bd4d29742405c7f1e6a82b1974d3d1f83c91b640fe5b86abd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangocms_snippet-5.0.0.tar.gz:

Publisher: publish-to-live-pypi.yml on django-cms/djangocms-snippet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djangocms_snippet-5.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djangocms_snippet-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa37d65a8ddde1323bea306f11f718fb7ee67cd29467517312811600e7529840
MD5 fc0714478c621240271baad837f31d96
BLAKE2b-256 e74bd72b01b6f0ba9985194d03cc81883621a82eef8066757d4836b7bdc9207e

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangocms_snippet-5.0.0-py3-none-any.whl:

Publisher: publish-to-live-pypi.yml on django-cms/djangocms-snippet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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