Skip to main content

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%}
''')

Metadata

Release files for jinja-script-block 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja-script-block 0.0.4
File Size Uploaded
jinja-script-block-0.0.4.tar.gz 2.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jinja-script-block 0.0.4
File Interpreter ABI Platform
jinja_script_block-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 4.8 kB

Release files / jinja-script-block-0.0.4.tar.gz

Download URL jinja-script-block-0.0.4.tar.gz
Size 2.4 kB
Tags Source
SHA-256 checksum
How to use checksums
519aa8051a8250f5c25e3b75a9fa95ee36dac9b8a15ab588f2e2d6341406c2dc
BLAKE2b-256 checksum
How to use checksums
ea4add39837f273c948d4f9ee137eec7669b6c06d71d65674583f8e22370edd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / jinja_script_block-0.0.4-py3-none-any.whl

Download URL jinja_script_block-0.0.4-py3-none-any.whl
Size 2.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a1951c3993524ae646648837a8f2089bc595a6eec5d4e73a2f4f8d2d3f62970
BLAKE2b-256 checksum
How to use checksums
c6db12c7066d925568244edd7da63b5e32157b8381cbad25116b3d0b28a07976
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page