M
M
m4son2021-06-06 22:33:30
JavaScript
m4son, 2021-06-06 22:33:30

How to make a filter in a loop in nunjucks?

There is an array of objects in which categories are passed

{% set categories = [
  {
    "id": 1,
    "slug": "shheben",
    "name": "Щебень",
    "parent": ""
  }, {
    "id": 2,
    "slug": "pesok",
    "name": "Песок",
    "parent": ""
  }, {
    "id": 3,
    "slug": "grunt",
    "name": "Грунт",
    "parent": ""
  } ...........
] %}


And there is an array of id's that need to be displayed . How do I filter them out?

{% set indexCat = [1, 2, 3, 4] %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
m4son, 2021-06-07
@m4son

Well, as an option, make another loop inside with iterating over the values ​​in the array and comparing it with id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question