Answers.Body: <p>I'd <a href="http://twig.sensiolabs.org/doc/filters/split.html" rel="nofollow">split the parameter string</a> into an array and then loop through the categories and use a conditional to check if the value already exists in the parameter. It's not so easy to describe in detail, that's why I added lots of comments to the code (untested!).</p>
  
  <p>To work in your other parameters (size, etc.), simply add them to your links exactly how <a href="http://buildwithcraft.com/docs/templating/craft.request#getParam" rel="nofollow"><code>craft.request.getParam()</code></a> returns them. Conditionally skip the output completely if the param is empty.</p>
  
  <pre class="lang-none prettyprint-override"><code>{# Get the parameter (e.g. 'red,blue,black') #}
  {% set currentParam = craft.request.getParam('color') %}
  
  {# Split the parameter string #}
  {% set arrCurrentParam = currentParam|split(',') %}
  
  {# Loop through categories to output the links #}
  {% for catOut in categories %}
  
      {# Define newParam var before loop #}
      {% set newParam = '' %}
  
      {# Loop through categories to compose the new parameter #}
      {% for catComp in categories %}
  
          {# Check if changes could happen in this loop #}
          {% if catOut.slug == catComp.slug %}
  
              {# Add category if it was currently NOT selected #}
              {% if catComp.slug not in arrCurrentParam %}
                  {% set newParam = newParam ~ ',' ~ catComp.slug %}
              {% endif %}
  
          {% else %}
  
              {# Add category if it was already selected #}
              {% if catComp.slug in arrCurrentParam %}
                  {% set newParam = newParam ~ ',' ~ catComp.slug %}
              {% endif %}
  
          {% endif %}
  
      {% endfor %}
  
      {# Remove leading comma #}
      {% set newParam = newParam|slice(1) %}
  
      {# Conditionally add param to link output #}
      &lt;a href="product?{{ newParam ? 'color=' ~ newParam }}"&gt;{{ category.slug }}&lt;/a&gt;
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T13:18:53.340Z
Answers.Text: you made my day!!!!
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T13:29:22.140Z
Answers.Text: Glad I could help, @Johannes. It was a challenge to think that one through though! But yeah, I'm sure I need something similar sooner or later, so it was definitely worth it :)
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T13:33:53.720Z
Answers.Text: I think more crafters need this too. Thank you again!
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T12:26:20.930Z
Answers.LastActivityDate: 2014-08-26T13:00:59.663Z
Answers.LastEditDate: 2014-08-26T13:00:59.663Z
Answers.UserDisplayName: carlcs
Body: <p>How do you update an URL with new params?</p>
  
  <p>I'm working on a search / filter entries page. I have multiple menu lists with categories in it. Like this:</p>
  
  <p><strong>Size:</strong>
  Small
  Medium
  Large</p>
  
  <p><strong>Color:</strong>
  Blue
  Red
  White
  Yellow</p>
  
  <p>So if the URL is <code>product?size=m</code> and I click on a link "Size → Large" then the URL needs to update to <code>product?size=m,l</code>. Click again on "Large" the <code>l</code> value of the sizes parameter needs to delete.</p>
  
  <p>If I then click on "Color → Red" the URL must be <code>product?size=m,l&amp;color=red</code>.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-26T10:14:56.920Z
Comments.Text: So you actually want to know how to compose the parameters and not how you "update an URL".
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-26T10:17:19.743Z
Comments.Text: :-) yes. Sorry, my english isn't good
Comments.UserDisplayName: Johannes Lamers
Tags: <templating><url><request><category><post>
Title: Compose URL POST parameters to filter entries by category?
ThreadText: # Compose URL POST parameters to filter entries by category?
  
  (Asked by: username_0 on 2014-08-26)
  
  How do you update an URL with new params?
  
  I'm working on a search / filter entries page. I have multiple menu lists with categories in it. Like this:
  
  **Size:**
  Small
  Medium
  Large
  
  **Color:**
  Blue
  Red
  White
  Yellow
  
  So if the URL is `product?size=m` and I click on a link "Size → Large" then the URL needs to update to `product?size=m,l`. Click again on "Large" the `l` value of the sizes parameter needs to delete.
  
  If I then click on "Color → Red" the URL must be `product?size=m,l&color=red`.
  
  **Tags:** templating, url, request, category, post
  
  > **Comments:**
  > **username_1**: So you actually want to know how to compose the parameters and not how you "update an URL".  
  > **username_0**: :-) yes. Sorry, my english isn't good  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-08-26. Score: 4 | Accepted answer
  
  I'd [split the parameter string](http://twig.sensiolabs.org/doc/filters/split.html) into an array and then loop through the categories and use a conditional to check if the value already exists in the parameter. It's not so easy to describe in detail, that's why I added lots of comments to the code (untested!).
  
  To work in your other parameters (size, etc.), simply add them to your links exactly how [`craft.request.getParam()`](http://buildwithcraft.com/docs/templating/craft.request#getParam) returns them. Conditionally skip the output completely if the param is empty.
  
  ```none
  {# Get the parameter (e.g. 'red,blue,black') #}
  {% set currentParam = craft.request.getParam('color') %}
  
  {# Split the parameter string #}
  {% set arrCurrentParam = currentParam|split(',') %}
  
  {# Loop through categories to output the links #}
  {% for catOut in categories %}
  
      {# Define newParam var before loop #}
      {% set newParam = '' %}
  
      {# Loop through categories to compose the new parameter #}
      {% for catComp in categories %}
  
          {# Check if changes could happen in this loop #}
          {% if catOut.slug == catComp.slug %}
  
              {# Add category if it was currently NOT selected #}
              {% if catComp.slug not in arrCurrentParam %}
                  {% set newParam = newParam ~ ',' ~ catComp.slug %}
              {% endif %}
  
          {% else %}
  
              {# Add category if it was already selected #}
              {% if catComp.slug in arrCurrentParam %}
                  {% set newParam = newParam ~ ',' ~ catComp.slug %}
              {% endif %}
  
          {% endif %}
  
      {% endfor %}
  
      {# Remove leading comma #}
      {% set newParam = newParam|slice(1) %}
  
      {# Conditionally add param to link output #}
      <a href="product?{{ newParam ? 'color=' ~ newParam }}">{{ category.slug }}</a>
  
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: you made my day!!!!  
  > **username_1**: Glad I could help, @username_0. It was a challenge to think that one through though! But yeah, I'm sure I need something similar sooner or later, so it was definitely worth it :)  
  > **username_0**: I think more crafters need this too. Thank you again!  
  
  ---
  
  