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

Template is not rendered for null value in array #27

Closed
pamelafox opened this issue Nov 21, 2011 · 3 comments
Closed

Template is not rendered for null value in array #27

pamelafox opened this issue Nov 21, 2011 · 3 comments

Comments

@pamelafox
Copy link

I have many templates like this:

<script id="stats-table-foodtypes-data-tmpl" type="text/x-jquery-tmpl">
{{#each dates}}
  {{#if data}}
   {{=$data}}
  {{else}}
    ?
  {{/if}}
{{/each}}
</script>

They expect an array of values, and they render one thing if the value is there and another thing if it is not. This worked in jQuery templates, but in jsRender, it appears that it does not call the template code at all for a null value. Is this the expected behavior?

@BorisMoore
Copy link
Owner

This is not currently supported, (in part because of the design for the behavior discussed in #7)

if you model your data to have an array of objects with properties (which may be undefined), rather than simply an array of strings that may be undefined as in ["a",,,"b"]) then you can get something close to your scenario:

{{#each languages}}
    {{#if name}}
        {{=name}}
    {{else}}
        NO
    {{/if}}
{{/each}}

languages: [
    { name: "English" },
    {},
    { name: "French" }
]

@pamelafox
Copy link
Author

Thanks for confirming that. I'll go through and change my data/templates accordingly.

@BorisMoore
Copy link
Owner

This behavior has been changed, and null or undefined elements in an array are rendered.
There are some related unit tests here, and on following lines:
https://github.com/BorisMoore/jsrender/blob/master/test/unit/jsrender-tests-no-jquery.js#L283
and also here: https://github.com/BorisMoore/jsrender/blob/master/test/unit/jsrender-tests-no-jquery.js#L198

http://borismoore.github.com/jsrender/test/unit-tests-no-jquery.html

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

No branches or pull requests

2 participants