Answers.Body: <p>Presumably you already have the code to retrieve the products you're after.</p>
  
  <p>So just loop through your products and merge your brands in to an array.  </p>
  
  <p>If the brands are just strings, just make an array of the strings, otherwise if they are relations, grab the ids.</p>
  
  <p>Something along these (untested) lines:</p>
  
  <pre><code>{% set brandStrings = [] %}
  {% set brandIDs = [] %}
  
  {% for product in products %}
      {# Either of these... #}
      {% set brandStrings = brandStrings|merge([product.brand]) %}
      {% set brandIDs = brandIDs|merge([product.brand.first().id]) %}
  {% endfor %}
  
  {# If strings, you've now got an array #}
  {# If Ids, and you need to get the names, you can do something like... #}
  
  {% set brands = craft.entries.id(brandIDs).find() %}
  
  {% for brand in brands %}
      {% set brandStrings = brandStrings|merge([brand.title]) %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-29T16:49:03.120Z
Answers.Text: I would recommend wrapping this with the {% cache %} tag to improve performance.
Answers.UserDisplayName: Maarten de Graaf
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-04T15:59:19.097Z
Answers.Text: Thanks for your response, i will check it out and see if it works.
Answers.UserDisplayName: Sebastián.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-16T01:18:29.927Z
Answers.Text: @Sebastián if this works for you, please accept the answer.
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-09T22:19:33.823Z
Answers.Text: Hey @Sebastián, can you please accept Jeremy's answer if it helped you, or update your question if it's not yet solved? (You can also post your own answer here if you solved the problem in a different way.)
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-28T05:23:28.407Z
Answers.LastActivityDate: 2016-02-28T05:23:28.407Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I´m working on a website of veterinary products. Some of the product fields are "category" and "brand".</p>
  
  <p>I have a product list page that shows a list of products of certain category, and I have a JS list to filter by "brand". So, what I need is to get a list of the brands from the products of this specific category ( without repeating ), so I can create the JS filter.</p>
  
  <p>Any ideas? :)</p>
  
Tags: <templating>
Title: Get a brand list of products for Javascript filter
ThreadText: # Get a brand list of products for Javascript filter
  
  (Asked by: username_0 on 2016-02-27)
  
  I´m working on a website of veterinary products. Some of the product fields are "category" and "brand".
  
  I have a product list page that shows a list of products of certain category, and I have a JS list to filter by "brand". So, what I need is to get a list of the brands from the products of this specific category ( without repeating ), so I can create the JS filter.
  
  Any ideas? :)
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-28. Score: 2 | Accepted answer
  
  Presumably you already have the code to retrieve the products you're after.
  
  So just loop through your products and merge your brands in to an array.
  
  If the brands are just strings, just make an array of the strings, otherwise if they are relations, grab the ids.
  
  Something along these (untested) lines:
  
  ```
  {% set brandStrings = [] %}
  {% set brandIDs = [] %}
  
  {% for product in products %}
      {# Either of these... #}
      {% set brandStrings = brandStrings|merge([product.brand]) %}
      {% set brandIDs = brandIDs|merge([product.brand.first().id]) %}
  {% endfor %}
  
  {# If strings, you've now got an array #}
  {# If Ids, and you need to get the names, you can do something like... #}
  
  {% set brands = craft.entries.id(brandIDs).find() %}
  
  {% for brand in brands %}
      {% set brandStrings = brandStrings|merge([brand.title]) %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_2**: I would recommend wrapping this with the {% cache %} tag to improve performance.  
  > **username_0**: Thanks for your response, i will check it out and see if it works.  
  > **username_1**: @username_0if this works for you, please accept the answer.  
  > **username_3**: Hey @username_0, can you please accept username_1's answer if it helped you, or update your question if it's not yet solved? (You can also post your own answer here if you solved the problem in a different way.)  
  
  ---
  
  