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

"name" variable shows even when empty data sent #103

Closed
aaronshaf opened this issue May 9, 2011 · 7 comments
Closed

"name" variable shows even when empty data sent #103

aaronshaf opened this issue May 9, 2011 · 7 comments

Comments

@aaronshaf
Copy link

I have a template that sometimes I need to render without sending any data to it. When I do so (either by sending no second parameter or by sending {}), the "name" template variable shows up as "data-id". Any ideas?

Here is my template:

https://gist.github.com/963527

Here is my render code:

$.tmpl('userTemplate').appendTo($('#user_add'))

@BorisMoore
Copy link
Owner

You mean the value of ${name} shows up as "data-id"? If you are passing in {}, then it is perhaps because you have something which sets a global variable 'name'.

@jc1arke
Copy link

jc1arke commented May 10, 2011

Just a suggestion, but you can just send through null instead of {}, as the template engine works with the jQuery.data() property system, thus the data-id as (data-id-variable: data-value-variable) :)

So basically your code will be:

var _array = [ {name: null}, {name: 'This should show'} ];
$.tmpl('userTemplate').appendTo($('#user_add'));

@aaronshaf
Copy link
Author

Is the problem perhaps with jQuery itself? "name" is not undefined on the global space on jquery.com, etc.

@JCInteractive, when passing null the problem remains.

@BorisMoore
Copy link
Owner

Can you put a complete (but minimal) test case which shows the issue, on jsbin or jsfiddle? It is not possible to determine the cause of the problem just from the gist above....

@aaronshaf
Copy link
Author

In the Chrome developer tools console the global "name" variable was still showing a value of "data-id", even when I cleared my web app entirely (i.e. a blank page with zero JavaScript). I suspected it had to do something with a Chrome extension. After disabling my extensions and then re-enabling them, and then restarting my browser, there is no longer a problem.

Oddly, the global "name" variable still is defined as a blank string in Chrome on every site, even with all extensions disabled.

Sorry if this is no help. Feel free to close the issue at your discretion.

@BorisMoore
Copy link
Owner

Yup - seems not to be anything to do with templates. Closing.

@dfsq
Copy link

dfsq commented Jun 17, 2011

name is a property of the window object.

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

4 participants