mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Add ynh_render_template helper to render templates with jinja2
This commit is contained in:
parent
9570832f42
commit
844b35589e
1 changed files with 17 additions and 0 deletions
|
@ -234,3 +234,20 @@ ynh_local_curl () {
|
||||||
# Curl the URL
|
# Curl the URL
|
||||||
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url"
|
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Render templates with Jinja2
|
||||||
|
#
|
||||||
|
# Attention : Variables should be exported before calling this helper to be
|
||||||
|
# accessible inside templates.
|
||||||
|
#
|
||||||
|
# usage: ynh_render_template some_template output_path
|
||||||
|
# | arg: some_template - Template file to be rendered
|
||||||
|
# | arg: output_path - The path where the output will be redirected to
|
||||||
|
ynh_render_template() {
|
||||||
|
local template_path=$1
|
||||||
|
local output_path=$2
|
||||||
|
# Taken from https://stackoverflow.com/a/35009576
|
||||||
|
python2.7 -c 'import os, sys, jinja2; sys.stdout.write(
|
||||||
|
jinja2.Template(sys.stdin.read()
|
||||||
|
).render(os.environ));' < $template_path > $output_path
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue