-
Notifications
You must be signed in to change notification settings - Fork 641
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
include strangeness #372
Comments
ping ? anyone ? This is really starting to bite me :( |
I'm not sure about the include, but you should be able to change it to a macro and solve your issue. They have better repetitive/scope handling: radio.html {% macro radio(property) %}
<p>radio.html: {{ property.name }}</p>
{% endmacro %} otherfile.html {% include "views/input/radio.html" %}
{% asyncEach property in model.properties %}
{% if property.ui %}
<h4>has ui</h4>
{{ radio(property) }}
{% endif %}
{% endeach %} |
thanks for the feedback - unfortunately, this workaround won't help - I think it's a problem with async in general. I am using a template loader where the template is grabbed from a db record. I also have several dozen templates that may be needed, each one specified by a property in the data object - and I actually don't know the names (these templates are / can be user-defined) thanks again for the clever workaround though |
Sorry, this is most likely a bug with async rendering. Async is somewhat experimental, but I doubt this is hard to fix. I'll take a look soon. |
I think I've solved the problem. While looking through the parser.js source, I came across this code parseIf: function() {
var tag = this.peekToken();
var node;
if(this.skipSymbol('if') || this.skipSymbol('elif')) {
node = new nodes.If(tag.lineno, tag.colno);
}
else if(this.skipSymbol('ifAsync')) {
node = new nodes.IfAsync(tag.lineno, tag.colno); so I thought i'd try using this mysteriously undocumented ifAsync ;) and it worked ... {% asyncEach property in model.properties %}
{% ifAsync property.ui %}
<h4>has ui</h4>
{% include "views/input/radio.html" %}
{% endif %}
{% endeach %} and I got the desired results is it ok to use ifAsync - or should if get converted to ifAsync automatically ? I also seem to have a problem with filters, i'll look into that as well |
@jmls Sorry I haven't looked at this until now. It definitely should automatically be converted into |
@jmls Make sure you marked your loader as async: http://mozilla.github.io/nunjucks/api.html#asynchronous |
Try it now! It should work |
The fix here seems wrong to me on its face (using an |
…r statements (fixes mozilla#372)" This reverts commit 7d4716f.
…r statements (fixes mozilla#372)" This reverts commit 7d4716f.
Reverted in 525abc2 -- re-opening this bug in case anyone wants to propose a better fix. (Perhaps an include should only trigger async-conversion for the |
* 2.x: (43 commits) Bump versions for dev. Update maintenance docs. Revert accidental changes to mocha.js. Bump version to 2.4.0. Update changelog. Merge pull request #694 from mariusbuescher/master Add note about include and blocks; update wrapping of templating docs. Merge pull request #688 from pra85/patch-1 Rename all test templates to use .j2 extension. Update changelog. Revert "make include statements trigger async conversion inside if/for statements (fixes #372)" Merge pull request #672 from TrySound/yargs Update changelog. Split backported and non-backported portions of #667 in changelog. More acks in changelog. Merge pull request #668 from oyyd/cn-doc Don't allow included templates to write to the including scope. Update changelog for opts.dev fix. Split include tests. Fix references to env dev opt. ...
I have a set of model data, where 3 of the model properties as has the property ui set to true. I also have this code:
radio.html
I get this rendered:
I see all of the property names, and the "has ui" for the three that have the property ui set to true.
so, now I only want the radio.html included if the ui option is set, so I move the include to within the {% if .. %}
but all I get now is
so, the if is definitely working (I get the "has ui" , but the include contents are not included
am I doing something wrong, or is there a bug here ?
The text was updated successfully, but these errors were encountered: