You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 22, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Jun 22, 2025. It is now read-only.
First of all : Eel is amazing ! This is a project I'd love to participate with.
One of the features I find lacking is the implementation of Jinja Variables. While the documentation and the options allow for inserting and using templates (with the jinja_templates argument in the start() function), I did not see any possibility to transfer variables within the templates.
It would be nice if this could be included either as a decorator or in a more "flask-like" fashion in the return of a function.
One solution that I tried to fiddle with but to no avail, was to create a decorator for the _static function (in the __init__.py) that seems to handle Jinja's template.render() function.
The idea was to create a global dictionary variable called jinja_variable and to update that variable depending on the page you want to visit.
If you were to include the jinja_variable in the kwargs of the start() function, wouldn't it be possible to dynamically change the output of the html page by accessing the required keys ?
You're definitely right that the implementation of jinja templating is a little lacking here, and being able to pass variables into the render calls does limit its utility.
I'd love to understand your use-case a little better so we can start to work out the best way forward. At the moment I'm not sure I understand your proposed solution or that it works for a general case. I'll start to have a think about it, but any details you can provide will help me understand where you're coming from.
I'm am a relatively inexperienced programmer, so the code above was simply something that I thought could be possible to integrate in the framework.
I'll try to be as short as possible, but here is my thought process:
Based on what Flask does, it is possible to nest Jinja's template.render() function inside flask's render_template() function (see templating.py line 116 to 141). This means the arguments of Flask's render_template() function are being passed on to Jinja's template.render() function.
Currently Eel does something similar in its _static() function.
This means that it should be possible to modify the _static() function as follows (or something similar)
def_static(path, **context):
"""Arguments: - path: path to the jinja template - context: dictionary with key = jinja variable name value = jinja variable value """response=Noneif (
'jinja_env'in_start_argsand'jinja_templates'in_start_args
):
template_prefix=_start_args['jinja_templates'] +'/'ifpath.startswith(template_prefix):
n=len(template_prefix)
template=_start_args['jinja_env'].get_template(path[n:])
ifcontextisnotNone:
response=btl.HTTPRespons(
template.render(context)
)
else:
response=btl.HTTPRespons(
template.render()
)
ifresponseisNone:
response=btl.static_file(path, root=root_path)
_set_response_headers(response)
returnresponse
By doing this, the last problem we are facing is to provide the **context argument to _static() in a way that is possible for the user to send variable for each html-page he/she wants to load. To do so, I have two options that come to mind:
the use of a decorator
create an independant function
In both cases, taking Eel's structure in consideration, we should pass 2 arguments:
a path_to_template
the context_dictionary
I believe it might end up looking something like this (and it is what I tried to make last week):
It's making building html in for-loops waaaay cleaner.
I would just pass an object to the template and get the values in a for-loop. But for Eel, I have to get the values in a for-loop, run the python command from javascript and do another for-loop for building the html.
And putting in values in html is in jinja itself muuch fancier.
Activity
samuelhwilliams commentedon Dec 6, 2019
Hey @Nootaku - thanks for your interest in Eel!
You're definitely right that the implementation of jinja templating is a little lacking here, and being able to pass variables into the render calls does limit its utility.
I'd love to understand your use-case a little better so we can start to work out the best way forward. At the moment I'm not sure I understand your proposed solution or that it works for a general case. I'll start to have a think about it, but any details you can provide will help me understand where you're coming from.
Thanks!
Nootaku commentedon Dec 9, 2019
Hey @samuelhwilliams - thank you for your swift answer.
I'm am a relatively inexperienced programmer, so the code above was simply something that I thought could be possible to integrate in the framework.
I'll try to be as short as possible, but here is my thought process:
template.render()function inside flask'srender_template()function (see templating.py line 116 to 141). This means the arguments of Flask'srender_template()function are being passed on to Jinja'stemplate.render()function._static()function._static()function as follows (or something similar)**contextargument to_static()in a way that is possible for the user to send variable for each html-page he/she wants to load. To do so, I have two options that come to mind:In both cases, taking Eel's structure in consideration, we should pass 2 arguments:
I believe it might end up looking something like this (and it is what I tried to make last week):
Cheers
Nama commentedon Sep 30, 2020
It's making building html in for-loops waaaay cleaner.
I would just pass an object to the template and get the values in a for-loop. But for Eel, I have to get the values in a for-loop, run the python command from javascript and do another for-loop for building the html.
And putting in values in html is in jinja itself muuch fancier.
forno96 commentedon Jul 6, 2021
There's some update on this topic?
I'm falling in love with this project and having the possibility to pass context to jinja would be super helpfull
eddyizm commentedon Jan 28, 2022
So am I correct in understanding that you can't pass a python variable to jinja or for example a data table?
Khharua commentedon Jul 24, 2023
I also hope this will be implemented, before or (probably) later! 👯
TadeasFrycak commentedon Aug 16, 2023
Hello, would it be possible to implement that, please? Just change of 1-2 lines of code in init.py is required:
Line 245 before:
response = btl.HTTPResponse(template.render())Line 245 after:
response = btl.HTTPResponse(template.render(_start_args['jinja_context']))And then optionally add
'jinja_context': Noneto_start_argson line 53