Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Showing pages that are published

Started by Claud Rusnac 9 years ago · 1 replies · 863 views
9 years ago

I have a template that is displaying a list of children, but the output also shows pages that are have "published: false".

TWIG
<ul class="list-group">
    {% for p in page.children if p != page %}
         <li class="list-group-item"> <a href="{{p.url}}"><i class="fa fa-angle-right" aria-hidden="true"></i> {{ p.title }}</a></li>
    {% endfor %}
</ul>

How do I exclude unpublished pages?

9 years ago

Hi
The page collection includes a "published" boolean so something like this should do what you need:

TWIG
{% if p.published %} 
{% endif %}
👍 1

Suggested topics

Topic Participants Replies Views Activity
Support · by TomW, 1 day ago
1 39 20 hours ago
Support · by TomW, 1 day ago
0 46 1 day ago
Support · by TomW, 6 days ago
6 131 2 days ago
Support · by Anna, 2 weeks ago
2 164 6 days ago
Support · by Anna, 4 weeks ago
1 333 4 weeks ago