where - Liquid Filter Reference
On this page
Description
Creates an list including only the objects with a given property value, or any truthy value by default.
| Property | Value |
|---|---|
| Return Type | list |
| Category | lists |
Examples
In this example, assume you have a list of pages and you want to show your help pages separately. Using where, you can create an list containing only the pages that have a \
```liquid %}
Help articles: {% for article in help_articles -%} - {{ article.title }} {% endfor %} ```
Output: All articles:\n- Support\n- Stock News\n- FAQs\n- About Us\n- Troubleshooting\n- Setup Guide\n\n\nHelp articles:\n- Support\n- FAQs\n- Troubleshooting\n- Setup Guide
Say instead you have a list of articles and you only want to show those that are published. You can use where with a property name but no target value to include all articles with a truthy \
```liquid %}
Published articles: {% for article in published_articles -%} - {{ article.title }} {% endfor %} ```
Output: All articles:\n- Support\n- Stock News\n- FAQs\n- About Us\n- Troubleshooting\n- Setup Guide\n\n\nPublished articles:\n- Support\n- FAQs