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

Global intrinsic functions like range not working in child template #166

Closed
jpcima opened this issue Oct 13, 2019 · 8 comments
Closed

Global intrinsic functions like range not working in child template #166

jpcima opened this issue Oct 13, 2019 · 8 comments
Labels
bug Something isn't working

Comments

@jpcima
Copy link

jpcima commented Oct 13, 2019

Hi, thanks for great work in the latest commits.
I find there remains an issue after applying the bugfixes.

In a child template, range-for appears non-working.
In the example, the first case is going to print Foo1,Foo2,Foo3,; but the same loop in an overriden block outputs nothing.

1.txt

{% block A %}
This is original block "A".
{% for i in range(3) %}Foo{{i+1}},{% endfor %}
{% endblock %}

2.txt

{% extends "1.txt" %}
{% block A %}
This is overriden block "A".
{% for i in range(3) %}Foo{{i+1}},{% endfor %}
{% endblock %}
@flexferrum
Copy link
Collaborator

Hm... You're right. I have to check this out. That's very strange behavior.

@flexferrum flexferrum added the bug Something isn't working label Oct 13, 2019
@flexferrum
Copy link
Collaborator

flexferrum commented Oct 13, 2019

The problem is in visibility of the global intrinsic functions. If you replace range(3) with [1, 2, 3] in the second template all will work fine.

@flexferrum flexferrum changed the title Range-for loops not working in child template Global intrinsic functions like range not working in child template Oct 13, 2019
@jpcima
Copy link
Author

jpcima commented Oct 13, 2019

Ok, about my personal globals which I insert using env.AddGlobal, these are recognized though.

@jpcima
Copy link
Author

jpcima commented Oct 14, 2019

I find something at this call site of values.Clone().
When passing true to the function, range() is working.

RenderContext innerContext = values.Clone(m_isScoped);

@flexferrum
Copy link
Collaborator

flexferrum commented Oct 14, 2019

BTW, globals should work with any value of this param. Because of globals. :)

@jpcima
Copy link
Author

jpcima commented Oct 14, 2019

I'm a bit confused about understanding the vocabulary regarding the various scope rules.

I observe that the range global is set into intParams, or extValues/m_externalScope as it's known on RenderContext side.

When it's cloned, it doesn't pass to the clone context, it's only m_globalScope which does, externals are replaced with an empty scope.

Maybe it's intParams and extParams are swapped at TemplateImpl::Render?

@flexferrum
Copy link
Collaborator

No. I suppose, problem is here:

SetupGlobals(intParams);

Globals should set up in extParams rather than intParams.

@jpcima
Copy link
Author

jpcima commented Oct 14, 2019

This small change fixes the problem on my side, and the test suite passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants