We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Unexpected behavior with array in theme.yaml

Curtis Blackwell October 30, 2014 by Curtis Blackwell

On 1.9.1, I've been keeping some global variables in a YAML file in my theme folder. I don't want to use pages because it's quicker for me to edit YAML and I don't have to use a bunch of {{ get_content }} tags (a lot of these values span multiple pages).

The plan was to namespace similar values with arrays.

project:
  description: This is a description of Project.
  slug: this-is-the-root-page-for-project
  features:
    -
      feature: Makes sandwiches!
      description: >
        With Project you can have all the made-to-order sandwiches you want. Made with the 
        freshest veggies and tastiest breads.
    -
      feature: Picks up your dog's poop!!!!!!1
      description: >
        Ain't nobody wanna manually pick up doggie doo. Let Project handle the doodles de la doge.
other_project:
  description: This is a description of Other Project.
  slug: this-is-the-root-page-for-other-project
  features:
    -
      feature: Karaoke
      description: >
        Convert all those majestic Good Charlotte songs in your ITunes library into karaoke-ready
        lady magnets.

Then in my templates, I could do things like:

<ul>
  {{ project:features }}

    <li>
      <h2>{{ feature }}</h2>
      <p>{{ description }}</p>
    </li>

  {{ /project:features }}
</ul>

(Maybe even something like {{ {title|lower|slugify:_}:features }}…{{ /{title|lower|slugify:_}:features }}, but I haven't tried that yet…)

Anyway, this was working great until I decided to move a header block into the front matter of a page to make a template reusable. The variables can't be parsed if they're in an array. For example, {{ project:slug }} stopped returning its value.

It does if I namespace with a string instead (example below), but I cry myself to sleep now.

project_description: This is a description of Project.
project_slug: this-is-the-root-page-for-project
project_features:
  -
    feature: Makes sandwiches!
    description: >
      With Project you can have all the made-to-order sandwiches you want. Made with the 
      freshest veggies and tastiest breads.
  -
    feature: Picks up your dog's poop!!!!!!1
    description: >
      Ain't nobody wanna manually pick up doggie doo. Let Project handle the doodles de la doge.

It does not work in settings.yaml, either. In case you're curious.

>>>>>>> Unanswered <<<<<<<
1 Reply
0 Followers