I've an array in my _config.yaml. Let's say
exclude_pages: [ "/404.html", "/search.html", "/atom.xml", "/rss.xml", "/index.html", "/sitemap.txt" ]
What I want to do is exclude these pages in the pages loop of site.pages. So following is the code that I'm trying.
{% for entry in site.pages %}
{% if site.exclude_pages contains entry.url %}
<!-- Do Nothing -->
{% else %}
<!-- Show Page -->
{% endif %}
{% endfor %}
But somehow it is not happening. All the pages are being ignored in this code.
Any idea what I'm missing here ?
Try :
exclude_pages: [ "index.html", "anyfolder/index.html" ]
Then loop with entry.path
not entry.url
:
{% for entry in site.pages %}
{% if site.exclude_pages contains entry.path %}
<!-- Do Nothing -->
{% else %}
<!-- Show Page -->
{% endif %}
{% endfor %}
According to template docs you my try to use Where Expression with contains
and unless
.
{{ assign entries = site.pages | where_exp:"item", "unless item.url contains site.exclude_pages" }}
{% for entry in entries %}
<!-- Show Page -->
{% endfor %}
See sample how a live code works to generate feed.json in my github site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With