Skip to main content

No project description provided

Project description

Jinja2 Script

Introduction

In ERB, custom functions can be written in the template. However with jinja2, the functions should be written in python, and must be included in the rendering environment.

Use Script Block

{% script modulename %}
  # Your Python Code that should be in .py
{% endscript %}

Define your python codes in script block. This is compiled before actual run starts.

To use compiled block, do it as following:

{{module.functions_you_defined()}}
{{module.values_you_defined()}}
{{module.function_with_arguments(1)}}
{{module.function_with_arguments_at_render(x)}}

How to use

from jinja_script_block import ScriptBlockExtension
from jinja2 import Environment

env = Environment(extensions=[ScriptBlockExtension])

env.from_string('''
{% script mymodule %}
class MyClass:
  containers = []
{% endscript%}
''')

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

jinja-script-block-0.0.4.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

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

jinja_script_block-0.0.4-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file jinja-script-block-0.0.4.tar.gz.

File metadata

  • Download URL: jinja-script-block-0.0.4.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for jinja-script-block-0.0.4.tar.gz
Algorithm Hash digest
SHA256 519aa8051a8250f5c25e3b75a9fa95ee36dac9b8a15ab588f2e2d6341406c2dc
MD5 a5ea5aec161835df3f00d59284ce9a11
BLAKE2b-256 ea4add39837f273c948d4f9ee137eec7669b6c06d71d65674583f8e22370edd0

See more details on using hashes here.

File details

Details for the file jinja_script_block-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for jinja_script_block-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a1951c3993524ae646648837a8f2089bc595a6eec5d4e73a2f4f8d2d3f62970
MD5 672b00b2228b6bbed3196bcf49bf368f
BLAKE2b-256 c6db12c7066d925568244edd7da63b5e32157b8381cbad25116b3d0b28a07976

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