<table> from yml file - where is my syntax wrong?


#1

Is there a good lad or lass out there who can help me see where my Liquid syntax is incorrect? I want to make a staff directory from a yaml file named staff.yml and it is in a _data directory. My default page w/ {{ content }} is correct and I’ve got {% include staff.html %} in the staff.md file.

My YML file is valid:

names:
-
Name: her name
Position: not boss
Email: [email protected]
EXT: Ext. 105
-
Name: his name
Position: not boss
Email: [email protected]
EXT: Ext. 104
-
20 more entries

My HTML is: 

<main id="content">
    <div class="container text-center">
        <div class="row justify-content-lg-center py-5">
            <div class="col-lg-8">
                <h2 class="mb-4">Staff Directory</h2>
                <h2 class="mb-4">Main phone number:   </h2>
              </div>
          </div>
      <div class="container text-center">
      <table class="table table-hover">
        <thead>
          <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Email</th>
            <th>EXT</th>
          </tr>
        </thead>
    <tbody>
    {% for names in site.data.staff %}
      <tr>
      <td>{{ site.data.staff.Name }}</td>
        <td>{{ site.data.staff.Position }}</td>
        <td>{{ site.data.staff.Email }}</td>
        <td>{{ site.data.staff.EXT }}</td>
    </tr>
      {% endfor %}
    </tbody>
  </table>
  </div>
  </div>
</main>

Really appreciate any help.

#2

try {{names.Name}}

see lots of good yml examples here:


#3

Thank you v much for your suggestion and link. You got me on the right track. The solution was to use the arbitrary but singular tense ‘name’, not plural ‘names’. This is the correct html:

<tbody>
    {% for name in site.data.staff %}
      <tr>
        <td>{{ name.Name }}</td>
        <td>{{ name.Position }}</td>
        <td>{{ name.Email }}</td>
        <td>{{ name.EXT }}</td>
      </tr>
          {% endfor %}
    </tbody>

#4

just an fyi - it does not matter what you call that particular part - names or name, or item or x, as long as you reference it in the code the same it will work.

I use item as the identifier in the loop - so for item in that-thing and then you use
item.name, item.date etc

I find item to be more obvious that it is the loop item, not a name or post or whatever. When learning jekyll originally I would see examples of loops with post as the identifier (not sure what that is called) and it clearly led to people like me thinking that post.name, post.date etc were actual things - but they only exist within the loop.


#5

thanks. i get it now. i will use item too going forward. really appreciate your help.