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

nest multiple templates inside one template #151

Closed
tinybyte opened this issue Aug 18, 2012 · 3 comments
Closed

nest multiple templates inside one template #151

tinybyte opened this issue Aug 18, 2012 · 3 comments

Comments

@tinybyte
Copy link

Say I have three templates:

<script id="entry" type="text/jsrender"></script>
<script id="head" type="text/jsrender"></script>
<script id="tail" type="text/jsrender"></script>

The layout is like

<entry>
<head/>
<tail/>
</entry>

I have arrays of entries, I have no way to embed head and tail template inside entry template, so that, jsrender will treat entry as a single template, and will works for [entries].

the {{for /}} can only bind a collection to one template. If the template is formed up with small templates, is there a way to compose all the small templates into a single template?

@tinybyte
Copy link
Author

I think there seems to have a way around, using {{for /}} even for a single loop. that way just import the template in to the other template, I don't know if it's the right way to do this, but I'll close the issue, since I've managed to get my problem solved.

@BorisMoore
Copy link
Owner

You can write:

{{for people}}...{{/for}}, or {{for people tmpl=.../}} to include an inline block or external template, iterated over an array, so the current item is the member of the array;

or {{for address}}...{{/for}}, or {{for address tmpl=.../}} to include an inline block or external template rendered once, but with current data item being the object;

or {{for tmpl=.../}} to include an external template with current data item undefined,

or {{for #data tmpl=.../}} to include an external template with current data item the same as the containing template context.

You can also write {{for [people] tmpl=.../}} to include an external template, rendered just once (rather than iterating) for an array, which is used in the following example: scenarios/05_arrays-plus-headers-and-footers

@BorisMoore
Copy link
Owner

The above comment gives some alternatives for template composition. Does that cover your requirements?

BTW to include markup in a comment on GitHub, you can wrap with 'backtick' characters, as in <script ...> or with triple backtick characters as in

<script>

See GitHub Flavored Markdown link above, when in edit mode.

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