vwochnik / jekyll-language-plugin

Jekyll 3.0-compatible multi-language plugin for posts, pages and includes
MIT License
115 stars 45 forks source link

Create a list of pages #4

Closed escapedcat closed 8 years ago

escapedcat commented 8 years ago

How could I get a list of pages and use the translated title form the subset?

Here the idea form the Jekyll example page: https://github.com/jekyll/example/blob/gh-pages/_includes/header.html#L15-L21

Basically I would like to create some sort of navigation. I'm not sure how to achieve something like this. Looks like I can't get the title through this:

{% for p in site.pages %}
  {{ p }}
{% endfor %}

Also my non existent ruby skills don't help...

vwochnik commented 8 years ago

You can do this exactly the way you want except that you have to check if the language is equal to the currently rendered language.

{% for page2 in site.pages %}
  {% if page2.language == page.language %}
    {% if page2.subset %}
      {% assign page2_title_key = page2.subset | append: '.title' %}
      <a href="{{ site.baseurl }}{{ page2.url }}">{% t page2_title_key %}</a>
    {% endif %}
  {% endif %}
{% endfor %}

I have changed the local page variable into page2 to retain access to the currently rendered page. Also, we are using the title from the page subset.

vwochnik commented 8 years ago

I have improved the example site and included the above snippet with an option to disable the navigation entry for a given page.

escapedcat commented 8 years ago

That helped me a lot. Thanks for your support! :relaxed: