ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic Parameters - Weird issue with categories in URL

September 05, 2012 5:04am

Subscribe [1]
  • #1 / Sep 05, 2012 5:04am

    Andrew Armitage

    86 posts

    Hi, I’m using dynamic parameters in a form as per:
    http://ellislab.com/expressionengine/user-guide/modules/channel/dynamic_parameters.html

    I’m using it to filter products and when I am on /products the filter works fine. However I have a list of categories and if I try using the filter when on a category page, so the url is something like /products/category/category-name the filter doesn’t work at all. I end up with a list of products by entry_id.

    Perhaps someone can tell me quickly if this is a known quirk or if it’s clearly something that I am doing wrong.

    Here’s my code:

    {exp:channel:entries channel="products" dynamic_parameters="orderby|sort|limit|category" status="open|Featured" limit="24" paginate="bottom" {sn_disable_member_comments}}
    
    <form method="post" action="{path='products/index'}" id="products-list-filter">
      <label for="orderby">Sort By:</label>
      <select name="orderby" id="orderby">
        <option value="date">Date Added</option>
        <option value="product_price">Price</option>
        <option value="title">Title</option>
      </select>
      <label for="sort">Order In:</label>
      <select name="sort" id="sort">
        <option value="asc">Ascending</option>
        <option value="desc">Descending</option>
      </select>
      <label for="limit">Limit:</label>
      <select name="limit" id="limit">
        <option value="10">10</option>
        <option value="20">10</option>
      </select>
      <input type="submit" value="Filter List" />
    </form><!-- #products-list-filter -->
    
    ...
    
    {/exp:channel:entries}

    Thanks for any help on this.

  • #2 / Sep 06, 2012 4:25pm

    Kevin Smith

    4784 posts

    Hi Andrew,

    When you say it doesn’t work at all, what do you mean exactly? Can you describe the behavior?

    In my test, the form worked, but since the form’s action is set to

    action="{path='products/index'}"

    ...it redirected to /products instead of /products/category/category-name. Is that the issue you’re talking about? The reason is because the form action doesn’t include the category and category-name segments in it. What happens if you try using something like this instead?

    action="{path='{segment_1}/{segment_2}/{segment_3}/{segment_4}'}"
  • #3 / Sep 07, 2012 4:45am

    Andrew Armitage

    86 posts

    Hi Kevin,

    Thanks for replying.

    What you say makes sense, that the category is dropped because it is no longer referenced in the URL so I tried what you suggested:

    action="{path='{segment_1}/{segment_2}/{segment_3}/{segment_4}'}"

    This does, as expected, keep the category and only list the category products. However I’m still having the issue that if I use the form on the category page to try and filter the products by price for example, that my products are displayed in the default order, by date.

    It’s strange because it uses the same code when the user is on /product, i.e. viewing all categories, and the filter works.

    Maybe there’s something in my code that I’m missing?

    {exp:channel:entries channel="products" dynamic_parameters="orderby|sort|limit|category" status="open|Featured" limit="24" paginate="bottom" {sn_disable_member_comments}}
      {if count == 1}
      {embed="products/filter"}
      <ul class="products-list group">
      {/if}
        <li>The product listing</li>
      {if count == total_results}
      </ul>
      {paginate}
        Page {current_page} of {total_pages} pages {pagination_links}
      {/paginate}
      {/if}
    {/exp:channel:entries}

    The products/filter code:

    <form method="post" action="{path='{segment_1}/{segment_2}/{segment_3}/{segment_4}'}" id="products-list-filter">
      <label for="orderby">Sort By:</label>
      <select name="orderby" id="orderby">
        <option value="date">Date Added</option>
        <option value="product_price">Price</option>
        <option value="title">Title</option>
      </select>
      <label for="sort">Order In:</label>
      <select name="sort" id="sort">
        <option value="asc">Ascending</option>
        <option value="desc">Descending</option>
      </select>
      <label for="limit">Limit:</label>
      <select name="limit" id="limit">
        <option value="12">12</option>
        <option value="24">24</option>
      </select>
      <input type="submit" value="Filter List" />
    </form>

    Thanks for all your help so far.

  • #4 / Sep 10, 2012 1:59pm

    Dan Decker

    7338 posts

    Hi Andrew,

    If you don’t mind, I’d like to pop in here!

    I tested with your code, slightly modified to match my channels and fields. I was able to sort by title, reliably on any page using dynamic parameters. I tested on ExpressionEngine 2.5.2, can you verify you are on the latest release?

    Cheers,

  • #5 / Sep 27, 2012 6:50am

    Andrew Armitage

    86 posts

    Hi Dan and Kevin,

    Sorry for going quiet on this one, I haven’t been working on this project for the last few weeks.

    Thanks for giving it a try for me. I was on 2.5.2 but have just updated to 2.5.3, just in case it resolved my issue - no such luck!

    Yes, I seem to be able to filter on just about anything other than categories, this is where it seems to fall over.

    If I try to use the filter on a category listing page, or even hard-code a chosen category into the filter then the page just seems to output my list of products by default order, completely ignoring categories altogether and ignoring any other dynamic parameters given.

    No matter what I do to the code its categories that seems to be the common issue every time.

    Thanks,
    Laura

  • #6 / Sep 28, 2012 11:08am

    Lisa Wess

    20502 posts

    Hi, Laura -

    I don’t see any category options in your drop-down; just limit, sort, and order.  Can you show us how you’re sending the category information to that tag?

  • #7 / Oct 01, 2012 4:21am

    Andrew Armitage

    86 posts

    Hi Lisa,

    The category is set in the url, so something like domain.com/products/category/bears. I need the form to automatically pick up segment_3, if there is one. If there isn’t then the category doesn’t need to be set.

    That would explain why Kevin suggested

    action="{path='{segment_1}/{segment_2}/{segment_3}/{segment_4}'}"

    Unfortunately this didn’t work for me and after further exploration it appears that when I try using the form while on a category listing page, so something like domain.com/products/category/bears, then I don’t get the results expected at all - all the dynamically chosen filters are ignored.

    Does that help clarify things? I appreciate I probably haven’t been as clear I as could have been.

    Thanks.

  • #8 / Oct 02, 2012 9:34am

    Dan Decker

    7338 posts

    Hi Laura, Andrew

    Taking a look back over the history here, you are telling channel entries to expect category information via POST by using the dynamic_parameter options. I think this is what Lisa was alluding too above.

    ExpressionEngine will look to POST data for that and not the URI, which is actually a GET string. If you take category out of the dynamic_parameters list, I think you will see consistent behavior.

    Can you give that a shot and let me know your results?

    Cheers,

  • #9 / Oct 02, 2012 11:08am

    Andrew Armitage

    86 posts

    Hi Dan,

    If I’ve understood everything correctly, then afraid not. I’ve taken category out of dynamic parameters as suggested but the form now doesn’t do anything when on a category listing page.

    Just to clarify my code at this stage:

    products/index

    {exp:channel:entries channel="products" dynamic_parameters="orderby|sort" status="open|Featured" limit="24" paginate="bottom" {sn_disable_member_comments}}
      {if count == 1}
        {embed="products/filter"}
        <ul class="products-list group">
      {/if}
      <li>...</li>
      {if count == total_results}
        </ul>
        {paginate}
          Page {current_page} of {total_pages} pages {pagination_links}
        {/paginate}
      {/if}
    {/exp:channel:entries}

    profiles/filter

    <form method="post" action="{path='{segment_1}/{segment_2}/{segment_3}/{segment_4}'}" id="products-list-filter">
      <label for="orderby">Sort By:</label>
      <select name="orderby" id="orderby">
        <option value="date">Date Added</option>
        <option value="product_price">Price</option>
        <option value="title">Title</option>
      </select>
      <label for="sort">Order In:</label>
      <select name="sort" id="sort">
        <option value="asc">Ascending</option>
        <option value="desc">Descending</option>
      </select>
      <input type="submit" value="Filter List" />
    </form>

    Note: I’ve taken limit out of dynamic parameters and the form as this is not longer required.

    When I use the form on just /products the filter works but if I’m on /products/category/somecategory then at this stage the filter doesn’t change the product list at all.

    Thanks for everyone’s help so far.

  • #10 / Oct 03, 2012 3:09pm

    Dan Decker

    7338 posts

    Alright, let’s dig in and get a handle on this.

    Be on the lookout for an email from EllisLab.

    ~

  • #11 / Oct 09, 2012 9:21am

    Kevin Smith

    4784 posts

    Dove into Laura’s installation and figured out the problem. For the benefit of onlookers, here was what I sent her:

    The reason dynamic parameters doesn’t work on your categories pages is because the field names are being changed by some JavaScript on the page. Since I don’t know the full ramifications of what that JS does, I haven’t tinkered with it. But if you’ll look at your products/filter template, you’ll see the select fields’ names. Those are set to work correctly, and they do on the non-category pages. But that JS changes those select field names, and when that happens, EE’s dynamic parameters no longer recognize the field names.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases