Skip to content

Instantly share code, notes, and snippets.

@gingerrific
Created February 22, 2018 23:41
Show Gist options
  • Save gingerrific/4b631c1e6dbbf6eb379a7b292de1a03d to your computer and use it in GitHub Desktop.
Save gingerrific/4b631c1e6dbbf6eb379a7b292de1a03d to your computer and use it in GitHub Desktop.
{% set filteredPosts = posts | selectattr("link") %}
{# filter posts to posts that actually contain a link #}
{% if filteredPosts and (filteredPosts | length) %}
@gingerrific
Copy link
Author

where posts is an array of objects

@gingerrific
Copy link
Author

{
    id:405128,
    image:"",
    link:"",
    link_summary:null,
    link_title:null,
    message:"Test"
}

@rmtobin
Copy link

rmtobin commented Feb 22, 2018

{% set filteredPosts = posts | selectattr("link") %}
{% for post in filteredPosts %}
    {% if post.link %}
          {# do something #}
     {% endif %}
{% endfor %}

Is this kind of your thought?

@rmtobin
Copy link

rmtobin commented Feb 22, 2018

{% set filteredPosts = posts | selectattr("link") %}
{% if filteredPosts %}
    {% for post in filteredPosts %}
        {# do something #}
    {% endfor %}
{% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment