Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

how can i add the for-loop index to the upload templ-form? #893

Closed
syllogismus opened this issue Dec 19, 2011 · 3 comments
Closed

how can i add the for-loop index to the upload templ-form? #893

syllogismus opened this issue Dec 19, 2011 · 3 comments

Comments

@syllogismus
Copy link

<script id="template-upload" type="text/html"> {% for (var i=0, files=o.files, l=files.length, file=files[0]; i {%=file.name%} {%=i%} > > the last line doesnt either work at all or the whole form breaks. how can i get the loop-index ? > > thx
@syllogismus
Copy link
Author

seems to be cut off:
https://gist.github.com/1499227

@blueimp
Copy link
Owner

blueimp commented Dec 20, 2011

The template will be rendered for each add call.
As long as the option singleFileUploads is set to true (which is the default), multiple selects/drops get split up into single add calls, so the index will always be 0.

From the JavaScript Templates documentation:

Note that the JavaScript Templates engine prints falsy values as empty strings.
That is, undefined, null, false, 0 and NaN will all be converted to ''.
To be able to print e.g. the number 0, convert it to a String before using it as an output variable:

<h3>{%=0+''%}</h3>

That is why the following won't print anything:

{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}
{%=i%}
{% } %}

@blueimp blueimp closed this as completed Dec 20, 2011
@syllogismus
Copy link
Author

hi and thx for taking the time looking into it. i took your advise and
chaged the options, and this was the only way i worked to build the form,
all other ways of supplying ended up in NOT shwoing the uploadform at all
(the list of files)
$('#fileupload').fileupload();

$('#fileupload').fileupload(
'option',
'singleFileUploads', 'false'
);

BUT, this still shows an index of 0:

{%=file.name%}

{%=i+''%}

so, no idea waz wrong here, i never used js-templates etc...

any ideas?

thx

On Tue, Dec 20, 2011 at 1:55 AM, Sebastian Tschan <
reply@reply.github.com

wrote:

The template will be rendered for each add call.
As long as the option singleFileUploads is set to true (which is the
default), multiple selects/drops get split up into single add calls, so
the index will always be 0.

From the JavaScript Templates documentation:

Note that the JavaScript Templates engine prints falsy values as empty
strings.
That is, undefined, null, false, 0 and NaN will all be converted to
''.
To be able to print e.g. the number 0, convert it to a String before
using it as an output variable:

<h3>{%=0+''%}</h3>

That is why the following won't print anything:

{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l;
file=files[++i]) { %}
{%=i%}
{% } %}

Reply to this email directly or view it on GitHub:

#893 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants