Friday, 15 August 2014

arrays - Printing tag in Jekyll prints entire post and other problems -



arrays - Printing tag in Jekyll prints entire post and other problems -

so i'm having this problem. want print categories name heading, categories several words haven't work far i've tried, i've solved setting tag , category in every post.

so after decision, tested 2 tags , 2 categories, tag1 cat1 , tag2 cat2, every tag has correspondent category. added tag/cat pairs of posts. algorithm looks this:

for loop in tags print category in heading tag loop in posts of category print post info

which, translated code, looks this:

{% assign = 0 %} {% tag in site.tags %} <p>checking i: {{ }}</p> <p>checking tag: {{ tag }}</p> <h1>checking cat: {{ site.categories[i] }}</h1> {% post in site.tags.tag %} <p>{{ post.title }}</p> {% endfor %} {% assign = + 1 %} {% endfor %}

and output is:

checking i: 0 checking tag: tag1 whole post checking cat: (nothing printed here) checking i: 0 checking tag: 0 checking cat: (nothing printed here)

and stops.

so questions are:

how access category? right prints nothing why print whole post contents after tag? why print 1 tag only? why isn't i incremented @ end of loop?

how access category? right prints nothing

site categories hash :

hash {"github issue"=>[#jekyll:post, #jekyll:post], "toto"=>[#jekyll:post, #jekyll:post], "jekyll"=>[#jekyll:post]}

site.categories['github issue'] homecoming post array site.categories[0] homecoming empty array

why print whole post contents after tag?

same reason above in {% tag in site.tags %}, tag hash see string representation of hash. if have 2 post in tag, see 2 post when print tag.

to tag name here : {{tag.first}}

why print 1 tag only?

it prints 2 tags

checking i: 0 checking tag: tag1 whole post checking cat: (nothing printed here) checking i: 0 checking tag: 0 checking cat: (nothing printed here)

this behavior unpredictable because you've declared tags , categories in _config.yml. not supposed because site.tags , site.categories set jekyll @ generation time depending on tags , categories found in posts. remove config , set tags in default front end matter config or in posts.

why isn't incremented @ end of loop? {% assign = | plus: 1 %}

see liquid documentation

possible solution {% tag in site.tags %} {% assign tagname = tag.first %} <h1>{{ tagname }}</h1> {% category in site.categories %} <h2>{{ category.first }}</h2> {% post in site.posts %} {% if post.tags contains tagname %} <h3>{{ post.title }}</h3> {% endif %} {% endfor %} {% endfor %} {% endfor %}

arrays loops jekyll

No comments:

Post a Comment