Skip to content

in_array or contains not working as expected #4066

@rustypaul

Description

@rustypaul

Hi Guys,

I'm having trouble checking to see if a value is in an array. I have a collection called websites, and it has an array of software which is an entries field pointing to another collection called software. I'm running the code below on the show page for the specific software entry

{{ collection:websites }}
            {{ software }}
                {{ if id == page:id }} 
                    <p>manual: {{ id }}</p>
                {{ /if }}
            {{ /software }}

            {{ if software | contains:{page:id} }}
                <p>in_array: {{ id }}</p>
            {{ /if }}
{{ /collection:websites }}

The manual loop running through the software loop correctly matches ids, but the contains loop doesn't. I get the same result using in_array.

The software entry id looks like this in its .md file

id: 61dec82d-101f-4417-a208-ad5d0d7dc34d

and the website entry looks like this

software:
  - 61dec82d-101f-4417-a208-ad5d0d7dc34d

Even if I manually add the id as a string to the contains variable it still doesn't recognise it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions