Template tags¶
codemirror_field_js_assets¶
Tag to render CodeMirror Javascript assets needed for all given fields.
Example
{% load djangocodemirror_tags %}
{% codemirror_field_js_assets form.myfield1 form.myfield2 %}
codemirror_field_css_assets¶
Tag to render CodeMirror CSS assets needed for all given fields.
Example
{% load djangocodemirror_tags %}
{% codemirror_field_css_assets form.myfield1 form.myfield2 %}
codemirror_field_js_bundle¶
Filter to get CodeMirror Javascript bundle name needed for a single field.
Example
{% load djangocodemirror_tags %}
{{ form.myfield|codemirror_field_js_bundle }}
param field: | A form field that contains a widget
|
---|---|
type field: | django.forms.fields.Field |
raises: |
|
returns: | Bundle name to load with webassets. |
rtype: | string |
codemirror_field_css_bundle¶
Filter to get CodeMirror CSS bundle name needed for a single field.
Example
{% load djangocodemirror_tags %}
{{ form.myfield|codemirror_field_css_bundle }}
param field: | A form field. |
---|---|
type field: | djangocodemirror.fields.CodeMirrorField |
raises: |
|
returns: | Bundle name to load with webassets. |
rtype: | string |
codemirror_parameters¶
Filter to include CodeMirror parameters as a JSON string for a single field.
This must be called only on an allready rendered field, meaning you must not use this filter on a field before a form. Else, the field widget won’t be correctly initialized.
Example
{% load djangocodemirror_tags %}
{{ form.myfield|codemirror_parameters }}
param field: | A form field. |
---|---|
type field: | djangocodemirror.fields.CodeMirrorField |
returns: | JSON object for parameters, marked safe for Django templates. |
rtype: | string |
codemirror_instance¶
Return HTML to init a CodeMirror instance for an element.
This will output the whole HTML needed to initialize a CodeMirror instance
with needed assets loading. Assets can be omitted with the assets
option.
Example
{% load djangocodemirror_tags %}
{% codemirror_instance 'a-config-name' 'foo_codemirror' 'foo' %}
param config_name: | |
---|---|
A registred config name. | |
type config_name: | |
string | |
param varname: | A Javascript variable name. |
type varname: | string |
param element_id: | |
An HTML element identifier (without
leading # ) to attach to a CodeMirror instance. |
|
type element_id: | |
string | |
keyword assets: | Adds needed assets before the HTML if True , else
only CodeMirror instance will be outputed. Default value is
True . |
kwtype assets: | Bool |
returns: | HTML. |
rtype: | string |