-
Notifications
You must be signed in to change notification settings - Fork 19
documenting a bit more the parsing of yaml with liquid #266
Comments
Yaml feels very natural to everybody who is familiar with object-oriented languages. It’s very similar to Json. Thats why it is not documented here.
You show a solution. What is the problem you are trying to solve? |
I'm not trying to solve any problem. I'm just saying that it would help new Jekyll users if the way liquid is used to parse yaml was more documented on the jekyll home page. (and then I gave two examples of things that are not so easy to guess at first sight, from the documentation available) |
I'm also looking for more information about looping through YML values. Suppose I have 30 pages in my site and want to loop through them in a specific order as described in the YML file? It would be great to have a code sample showing how to do that. |
The Liquid creators have an introduction video on top of the official documentation. Try to put this in your numbers:
- zero
- one
- two Now you can loop over the {% for number in site.numbers %}
{{ number | upcase }}
{% endfor %} The result is:
The array items are accessible over the index too. {{ site.numbers[1] | upcase }}
#=> ONE For more useful examples checkout the Jekyll Snippets. You can find a heavier Liquid usage in my Compress HTML layout. |
The official documentation of liquid does not mention yaml at all, and the parsing of yaml files with liquid is a feature that is implemented by Jekyll (or maybe by some ruby package it relies upon). It does not come from the original liquid specs. Am I right, or am I missing something? |
You are right.
|
@baptistecalmes Feel free to expand the documentation in the jekyll/jekyll repository. It's open.
|
I was afraid you'd say that ;-). However, before offering some kind of contribution, I was hoping someone would point me to the right place that I had missed. If no one else reacts, I'll think about it. Thanks anyway for your time and suggestions. |
@penibelst Thanks for the concise examples and quality links. Made a note of the links to stay in tune with. |
I have a problem like this, I am new and don't know where to get started or how to call what im looking for. I have a data set in YAML looking something like this (there is 100+ of these sets)
And I loop though them using
But now I want to create a separate page where only the 'games' that do have a release date, so
But I don't know where to start or how to call what im doing to get a proper Google search term, anyone tips? |
mvaneijgen - I think you just need a where clause: see http://jekyllrb.com/docs/templates/ for a little documentation. It should be easy to do. Also, it looks like you are putting the data set in the config.yml? you can also put it in a data file (http://jekyllrb.com/docs/datafiles/) which I find very handy. I find StackOverflow to be the best source of examples, that and random blogs. I think their is an infinite number of things that seem obvious to the one trying to implement it, but that creates a bit of a documentation problem. |
|
Friendly user on Reddit had pointed me to the solution
This works for me |
@mvaneijgen This can not work. The iteration variable is
If you know about truthy and falsy in Liquid, you can simplify it.
|
This repository is no longer maintained. Please search for your issue on Jekyll Talk, our new community forum. If it isn't there, feel free to post to the Help category and someone will assist you. Thanks! |
First, I'm new to jekyll, and I think it's great.
I'm struggling a bit with the parsing of yaml files using for loops.
My understanding is that there are basically two types of objects that one might find in yaml files: lists and so-called "associative arrays" that are some kind of dictionaries. These two structures can be nested, and basically that is all there is to it. (See http://en.wikipedia.org/wiki/YAML)
I find it hard to guess the exact liquid syntax that can be used in jekyll as how to reach a particular element, and I find that the online documentation (which is great for most purposes) is a bit too scarce, unless I have missed some part of it.
So, my suggestion would be to:
This could be done by expanding the section:
http://jekyllrb.com/docs/datafiles/#the-data-folder
or by adding a new section.
I understand that this is borderline between liquid and jekyll, but it's such an important practical step to use the full power of jekyll that it definitely would help new users a lot if more details were given.
To make things concrete, here is a problem for which I only have an ugly solution, and I still wonder if its the best. Say one want to use the following yaml content in a file mylist.yaml
and you want to loop over the items of the list and access the keys and values. Then, the only solution I could find was to write
and it took me a while to figure it out (it doesn't seem obvious that one needs to nest two for's, especially since the second one only ever loops through one iteration).
Another example: to actually use a variable in the description of the file name in the loop
one cas surround it in brackets, like:
(which will loop in site.data.foo if page.layout is foo).
Again, it took me a while to figure out this syntax.
Etc.
Maybe I am missing some documentation somewhere, but I did do a good search before posting this suggestion.
Anyway, great job, keep up the good work ;-)
The text was updated successfully, but these errors were encountered: