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

Comments

Projects
None yet
2 participants
@pamelafox

pamelafox commented Nov 21, 2011

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

This comment has been minimized.

Show comment
Hide comment
@BorisMoore

BorisMoore Nov 21, 2011

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" }
]
Owner

BorisMoore commented Nov 21, 2011

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

This comment has been minimized.

Show comment
Hide comment
@pamelafox

pamelafox Nov 29, 2011

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

pamelafox commented Nov 29, 2011

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

@BorisMoore

This comment has been minimized.

Show comment
Hide comment
@BorisMoore
Owner

BorisMoore commented Mar 12, 2012

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

@BorisMoore BorisMoore closed this Mar 12, 2012

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