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.3.tar.gz (2.3 kB view hashes)

Uploaded Source

Built Distribution

jinja_script_block-0.0.3-py3-none-any.whl (2.4 kB view hashes)

Uploaded Python 3

Supported by

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