Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need support for nested data in get_undeclared_template_variables method #538

Open
roynrishingha opened this issue Apr 16, 2024 · 1 comment

Comments

@roynrishingha
Copy link

roynrishingha commented Apr 16, 2024

Feature Details

In a .docx file, if a variable defined as {{ foo }} , the get_undeclared_template_variables method returns me foo which is what I expect. But if the variable is defined as {{ foo.bar }}, it still returns only foo. It does not recursively look for nested variables.

In the method implementation, I noticed that, first jinja AST is built and passed to find_undeclared_variables of the meta module of jinja2. I don't get it why the AST does not help us getting the nested variables.

Solution

I do not have any idea of how this can be solved. Therefore I'm opening this issue in a hope that someone from community will help me out.

@luckylinux
Copy link

luckylinux commented Apr 18, 2024

I think I have a (Maybe) Related Issue, although with a different Outcome.

If I have {{ foo }} in the template, then the get_undeclared_template_variables method returns nothing if foo is defined.

However, if I have {{ foo["Bar"] }} in the template, then the get_undeclared_template_variables method returns foo, even though foo["Bar"] is defined and the Template renders correctly (and replaces those Occurrences with the required Values).

Although maybe the Usual Python Dict way of accessing elements foor["Bar"] is NOT correct in Microsoft Word / Libreoffice (since both Single Quotes and Double Quotes are "weird", i.e. NOT the "normal" Single or Double quotes you would use in Python, BASH Scripts, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants