Reputation: 123
I am building a database with Jekyll, and would like an entry in the database to have links to every other page in the same category. For example, every page in category 'a' will be listed with a button with this code snippet:
{% for page in site.pages %}
{% if page.layout == 'a' %}
<ul class="actions">
<li><a href="/people/{{ page.title | remove: ' ' | strip_newlines | downcase | md5 }}/" class="button alt small">{{ page.title }}</a></li>
</ul>
{% endif %}
{% endfor %}
The problem I'm having is by listing every page it will include the current page. Is there one more layer of logic I can add that will make this snippet list every page in the category except the page it is currently on? Thank you!
Upvotes: 2
Views: 261
Reputation: 23962
Current page will hold its data in the page
variable, so you need to choose another name to loop through pages.
Then add another condition to avoid process current page detecting its id:
{% for onepage in site.pages %}
.. If same category...
{% unless page.id == onepage.id %}
...
{% endunless%}
..endif...
{% endfor %}
Upvotes: 2
Reputation: 123
I also figured out a way to do it with if statements, I'll just post it for posterity.
{% for apage in site.pages %}
{% if apage.layout == 'a' %}
{% if page.url != apage.url %}
<ul class="actions">
<li><a href="/entries/people/{{ apage.title | remove: ' ' | strip_newlines | downcase | md5 }}" class="button alt small">{{ apage.title }}</a></li>
</ul>
{% endif %}
{% endif %}
{% endfor %}
Upvotes: 0