Designer News
Where the design community meets.
over 7 years ago from Adam Rasheed, Frontend Software Engineer
So I would have to have a separate YAML file for every category?
How would I have everything in a single YAML file? So I can write a loop that populates the categories and the list within those categories from a single YML file.
How would I go about doing that?
The more that I think about this, the more that I think you should keep it simple and store it in YAML front matter (especially for a site without a lot of pages). You're just using this data on one page?
Front matter for the page:
designers: - name: 'Designer name' src: 'http://example.com' - name: 'Designer name' src: 'http://example.com' - name: 'Designer name' src: 'http://example.com' photographers: - name: 'Photographer name' src: 'http://example.com' - name: 'Photographer name' src: 'http://example.com'
Reference within a for loop with: page.designers[forloop.index0].name
or page.photographers[forloop.index0].src
.
You can use the same structure in a data
YAML file. In that case you’d use a variable like site.data.people.designers[forloop.index0].name
. But you can see why keeping it all in one file can be a bit difficult, especially if you’re only using the data once. A variable reference like that is a pain and is so specific that it’s unlikely to require reuse.
If you’re really only referencing the data once, put the YAML data in the front matter (between the dashes at the start of the HTML or Markdown doc). If you’re reusing it elsewhere, make a new data file for each thing you want to reference on your site (like photographers.yml
, designers.yml
and so on).
Designer News
Where the design community meets.
Designer News is a large, global community of people working or interested in design and technology.
Have feedback?
Does your syntax look like this?
- name: 'Designer name' src: 'http://example.com' - name: 'Designer name' src: 'http://example.com' - name: 'Designer name' src: 'http://example.com'
Give that a shot.