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

Add a way to acceed to loop data #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

bubbatls
Copy link

when using block {{#anArray}} {{/anArray}}
You may accedd to loop datas with @Index @Arrayindex and @Length
{{@Index}} / {{@Length}}
will output
1 / 12
2 / 12
3 / 12
...
@Arrayindex start at 0 instead of 1

Maybe there is a better way to do this, but something is really missing on this point

when using block {{#anArray}} {{/anArray}}
You may accedd to loop datas with @Index @Arrayindex and @Length
{{@Index}} / {{@Length}}
will output
1 / 12
2 / 12
3 / 12
...
@Arrayindex start at 0 instead of 1
@jrmax
Copy link

jrmax commented Feb 10, 2014

+1
this would be great!

@rcampbel
Copy link

This looks like LOGIC
-1

@dgmike
Copy link

dgmike commented Mar 17, 2014

Nice 👍

@dasilvacontin
Copy link
Collaborator

Maybe a helper function/plugin.

@dgmike
Copy link

dgmike commented Dec 22, 2014

Is there in spec?

@Arrayindex
Copy link

I am @Arrayindex

@rcampbel
Copy link

rcampbel commented Nov 1, 2017

So, just out of curiosity, this branch only handles when the value is an object.

  • Are there going to be unit tests that go along with this change?
  • What would the side effects be when the value is truthy/falsy??

Example
Data :

{
  "booleanValue": true,    // true
  "stringValue": "Some String",    // true
  "emptyString": "",    // false
  "whiteSpace": "    ",    // true
  "numericFalseValue": 0,    // false
  "numericTrueValue": 1    // true
}

Template:

{{#booleanValue}} {{@index}} / {{@length}} {{/booleanValue}}
{{#stringValue}} {{@index}} / {{@length}} {{/stringValue}}
{{#emptyString}} {{@index}} / {{@length}} {{/emptyString}}
{{#whiteSpace}} {{@index}} / {{@length}} {{/whiteSpace}}
{{#numericFalseValue}} {{@index}} / {{@length}} {{/numericFalseValue}}
{{#numericTrueValue}} {{@index}} / {{@length}} {{/numericTrueValue}}
  • How would this work with nested data??

Example
Data :

{
  employees : [
    {
      hasLeftCompany : false,
      firstName: "John"
    },
    {
      hasLeftCompany : true,
      firstName: "Jane"
    }
  ]
}

Template:

<table>
  <thead>
    <tr>
      <th colspan="2">Active Employees</th>
    </tr>
    <tr>
      <th></th>
      <th>First Name</th>
    </tr>
  </thead>
  <tbody>
    {{#employees}}
      {{^hasLeftCompany}}
        <tr>
          <td>{{@index}}</td>
          <td>{{fisrtName}}</td>
        </tr>
      {{/hasLeftCompany}}
    {{/employees}}  
  </tbody>
</table>

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

Successfully merging this pull request may close these issues.

None yet

6 participants