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

Nested Templates Via Ajax #37

Closed
jwynveen opened this issue Dec 29, 2010 · 2 comments
Closed

Nested Templates Via Ajax #37

jwynveen opened this issue Dec 29, 2010 · 2 comments

Comments

@jwynveen
Copy link

I ajax my templates in from a file. In the root template in that file, I'm trying to render a nested template with {{tmpl}} that is in the same file I ajaxed in. However, I get an error in FireBug that c.tmpl is not a function. It seems it can't find the second template in that file. Is there a way to get this working or is this a bug?

@BorisMoore
Copy link
Owner

Difficult to answer without knowing how you are 'ajaxing in' your templates. One way, which I would encourage, is to create a remote script file to load the templates as named templates, from strings:

Mytemplates.js:
$.template( "rowTemplate", “<tr>…</tr>” ); 
$.template( "liTemplate", “<li>…</li>” );

Then either include it statically, as <script src=”mytemplates.js” …> or use jQuery.getScript or equivalent to load dynamically. Render as named templates using $.tmpl("rowTemplate", data) or {{tmpl(data) "liTemplate"}}.

Can you test whether this approach works for you?

@jwynveen
Copy link
Author

That method works. However, I found a more efficient way to do it. When I receive the html response from my ajax call that has all of the templates in it, I use $('script', response).each(..) to loop through every <script> tag in the file and create a named template for each based on their id attribute.

This issue was closed.
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