I am trying to insert some data inside desk.html
<script>
settings = {
hash = {{ msg_hash }}
}
</script>
msg_hash is generated by a function but since jinja doesn’t allows python code inside templates. Which is the best way to pass the variable msg_hash to the template desk.html
call your msg_hash function in desk.py inside get_context() then return msg_hash value:
# this needs commit
csrf_token = frappe.sessions.get_csrf_token()
frappe.db.commit()
boot_json = frappe.as_json(boot)
# remove script tags from boot
boot_json = re.sub("\<script\>[^<]*\</script\>", "", boot_json)
return {
"build_version": get_build_version(),
"include_js": hooks["app_include_js"],
"include_css": hooks["app_include_css"],
"sounds": hooks["sounds"],
"boot": boot if context.get("for_mobile") else boot_json,
"csrf_token": csrf_token,
"background_image": boot.user.background_image or boot.default_background_image,
"google_analytics_id": frappe.conf.get("google_analytics_id")
}
2 Likes