# \_data subfolders & variable assignment

**URL:** <https://talk.jekyllrb.com/t/data-subfolders-variable-assignment/7375>\
**Category:** Help\
**Created:** [May 27, 2022, 12:16pm UTC](https://talk.jekyllrb.com/t/data-subfolders-variable-assignment/7375 "2022-05-27T12:16:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlplummer](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jlplummer/32/4681_2.png) [@jlplummer](https://talk.jekyllrb.com/u/jlplummer)\
**Post date:** [May 27, 2022, 12:16pm UTC](https://talk.jekyllrb.com/t/data-subfolders-variable-assignment/7375/1 "2022-05-27T12:16:37Z")

</div>

Hello,

I’m attempting to create a character-bio type page for a web comic. I’ve been able to get this to work using a single .yml file in \_data, but I’m trying to incorporate the subfolder concept in the documentation ([Data Files → Subfolders](https://jekyllrb.com/docs/datafiles/#subfolders)). This would let me create an individual .yml file for each character as opposed to having one large file with all of the characters.

I’m able to get the page to iterate through each .yml file in the subfolder, but when I try to access a specific data item inside of one of those .yml files, it comes back empty (screenshot below).

**\_data folder structure:**

```auto
├───_data
│ │ something.yml
│ │
│ └───characters
│ slimey.yml
│ uncleultross.yml

```

**Contents of the .yml files in \_data/characters:**

```nohighlight
- name: Slimy
  description: Everything needs a cute mascot character, right?
  image_path: /assets/images/character-placeholder.png

```

```nohighlight
- name: Uncle L. T. Ross
  description: This is his description.
  image_path: /assets/images/character-placeholder.png

```

**Here is my .html file (this is a top-level page, not a post or layout).**

```nohighlight
---
layout: default
---
<div>Character stuff here!</div>
<div>This comes from the folder</div>

<div class="row">
  <div class="col">
    <p class="phthalo-green">site.data.characters: {{ site.data.characters }}</p>

    {% for character_hash in site.data.characters %}

    <p>Character_hash: {{ character_hash }}</p>
    <p>Character_hash[0]: {{ character_hash[0] }}</p>
    <p>Character_hash[1]: {{ character_hash[1] }}</p>

   <!-- This is where the issue may be? -->
    {% assign character = character_hash[1] %}
    <p>char: {{ character }}</p>
    <p>Name: {{ character.name }}</p>

    {% assign char2 = character_hash[0] %}
    {% assign char3 = site.data.characters[char2]%}
    <p>char3.name: {{ char3.name }}</p>
      <div class="card mb-3 asparagus" >
        <div class="row g-0">
          <div class="col-md-4">
            <img src="{{ character.image_path }}" class="img-fluid rounded-start" alt="Character Placeholder">
          </div>
          <div class="col-md-8">
            <div class="card-body">
              <h5 class="card-title">{{ character.name }}</h5>
              <p class="card-text">{{ character.description }}</p>
              <!-- <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p> -->
            </div>
          </div>
        </div>
      </div>
    {% endfor %}
  </div>
</div>

```

**This is the output that I get:**

 ![Screenshot 2022-05-27 081257](https://canada1.discourse-cdn.com/flex030/uploads/jekyllrb/original/2X/9/9886191f584c68a17379fb7e8fce172d5f98a759.jpeg)

Do I misunderstand the intent behind the \_data subfolders?

Please let me know if I missed any key details for the question.

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [May 27, 2022, 1:58pm UTC](https://talk.jekyllrb.com/t/data-subfolders-variable-assignment/7375/2 "2022-05-27T13:58:13Z")

</div>

I think the issue is that the individual character files contain single-element lists, rather than objects. I.e. this is a one-element list:

```nohighlight
- name: foo
  desc: foo bar

```

And this is a single object (note removal of `-` and indentation):

```nohighlight
name: foo
desc: foo bar

```

Probably you originally had a multi-element list in a `character.yml` file, which you split into individual files without removing the list notation.

---

<div class="post-metadata">

**Author:** ![jlplummer](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jlplummer/32/4681_2.png) [@jlplummer](https://talk.jekyllrb.com/u/jlplummer)\
**Post date:** [May 27, 2022, 2:05pm UTC](https://talk.jekyllrb.com/t/data-subfolders-variable-assignment/7375/3 "2022-05-27T14:05:37Z")

</div>

Yes, that was it. Thank you so much. My apologies, I need to brush up on yaml more apparently. 🙂

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [May 27, 2022, 2:11pm UTC](https://talk.jekyllrb.com/t/data-subfolders-variable-assignment/7375/4 "2022-05-27T14:11:30Z")

</div>

A side note: one reason it is was difficult to debug this problem is because lists are rendered by concatenation, which means single-element lists are “invisible”. To truly see the value of a variable you must use the [`inspect` filter](https://jekyllrb.com/docs/liquid/filters/#inspect). Example:

```auto
---
mylist: [1,2,3]
---
list: {{ page.mylist }}
inspected list: {{ page.mylist | inspect }}

```

Result:

```nohighlight
list: 123
inspected list: [1, 2, 3]

```
