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

Layout template #124

Closed
StrouMfios opened this issue May 21, 2012 · 2 comments
Closed

Layout template #124

StrouMfios opened this issue May 21, 2012 · 2 comments

Comments

@StrouMfios
Copy link

I downloaded the latest version of jsRender and I have some issues regarding the layout template.

I used to use

{{for ListData tmpl="#LayoutTmpl" ~variable=value Layout=true /}}
but after a quick view in latest version of jsRender code I saw that in the the "Layout" variable renamed to "isLayout".

I tried this

{{for ListData tmpl="#LayoutTmpl" ~variable=value isLayout=true /}}

< script id="LayoutTmpl" type="tex t/x-jsrender" >
{{:#parent.parent.data.propertyName}}
{{if #data.length > 0}}
{{for #data}}
{{:propertyName}}
{{/for}}
{{else}}
do something
{{/if}}
</ script>

but with no luck. The nested layout template is rendered as a normal template and since the data object isn't recognized as a type of list, I am getting the "do something" so many times as the length of the list.

The same code works with a previous version (// informal pre beta commit counter: 6)

How can I fix this for the latest version?

Thanks in advance

@BorisMoore
Copy link
Owner

The design was changed in a recent commit:
fc7a28b

There is a new sample here: See http://borismoore.github.com/jsrender/demos/scenarios/05_arrays-plus-headers-and-footers.html

Rather than setting layout=true, or isLayout=true, you simply need to pass your data array wrapped as an array, {{for [myArray]...}} so JsRender will treat the myArray as a single object. This is a similar to how you bind to arrays in jQuery: $([myArray]).bind(...).

This change follows feedback (see issue 118 for example) around the layout template feature.

Please reopen if this new approach does not enable your scenario... thanks.

@StrouMfios
Copy link
Author

Thanks a lot Boris!!

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