typemill / typemill

Typemill is a lightweight, flat-file CMS designed for simple, fast, and flexible website and eBook creation using Markdown.
https://typemill.net
MIT License
427 stars 60 forks source link

Tell inside twig if the page is a post or not #376

Closed grazianobolla closed 2 months ago

grazianobolla commented 1 year ago

I added disqus to my site, but I cant find a way to tell if a page is a post or not in order to do something like:

{% if page_is_post %}
<div>render disqus bla bla...</div>
{%endif%}

I found a variable (not listed in the docs) called 'home' which seems to be true only when the user is in the homepage (which actually works for me) but I dont know if there is something else or a better way to do it, thanks!

trendschau commented 2 months ago

Sorry for not answering, I was completely block and try to clean up all issues now.

If you have a post, then the page is inside a folder. So it should be possible to find out with the {{ item }}-tag. Each item-tag has sub-items like "thisChapter", "nextPage", and "prevPage" to build navigations. thisChapter is the parent folder. And the parentFolder holds the information, if it contains pages or posts. So you should be able to do it like this:

{% if item.thisChapter AND item.thisChapter.contains == 'posts' %}
<div>render disqus bla bla...</div>
{% endif %}

I did not test it, but something like that should work.

Sorry again for late reply, maybe it helps someone with a similar question.