2

I have a question concerning the function of research in Grid field, specifically on a relationship field. Here's my problem:

I have a grid field for a product catalogue, with many fields for each product specification. One of them is a relationship field, that catch the data from a "brand" channel. So I have

{exp:channel:entries channel="my_channel"}

{catalogue}

{catalogue:brand}

{catalogue:brand:brand_title}

{/catalogue:brand}

{/catalogue}

{/exp:channel:entries}

that shows me all the products on www.mysite.com/catalogue.

What I would like is to filter those products based on the brand, something like

segment_2 == brand_title

that will show, for example, all the Apple products on www.mysite.com/catalogue/apple and so on.

Is it possible? Thanks to everyone who will help me.

2

Have you considered the reverse? e.g. start at the brand channel and get the parents (e.g. products)? Might be more easy.

Grid is quite new and the relationship field also was recently changed (2.6) search and categories are not mature i guess (Relationship field tag parameters). Have you also tried Grid search:column_name=?


edit as noted in the comments below: "Currently it is not possible to get the parents of a relationship field that is inside of a Grid field".

An alternative is to use stash to store each item in a list, and store the brand with each item. On output or on setting the list, you can filter by brand. (e.g. match= against=)

See examples on: https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Aset_list%7D

{exp:stash:set_list name="my_list" parse_tags="yes"}
  {exp:channel:entries channel="my_channel"}
    {catalogue}
      {stash:item_title}{catalogue:title}{/stash:item_title}
      {catalogue:brand}
        {stash:item_brand}{catalogue:brand:brand_title}{/stash:item_brand}
      {/catalogue:brand}
    {/catalogue}
  {/exp:channel:entries}
{/exp:stash:set_list}
...
{exp:stash:get_list .... }
  • I need the "catalogue" channel to be separated from the "brand" channel, for member access purpose. I've tried {catalogue search:brand="=MyBrand"}, and I have no results (catalogue list is blank.) I also tried {catalogue search:brand:brand_title="=MyBrand"} and {catalogue search:brand_title="=MyBrand"} but it shows me the entire catalogue, with all the products. – Elena Feb 4 '14 at 11:53
  • Yes, i understand the separate channels, but if you want to filter by brand, you can instead start your search from the brand channel (apple) and then get the catalogue items by accessing the parents. – GDmac Feb 4 '14 at 15:46
  • According to EE documentation: "The Relationships field can be used as a Grid field column. Currently it is not possible to get the parents of a relationship field that is inside of a Grid field. You can also not use Relationships inside of a Grid field that does not store Channel data." ellislab.com/expressionengine/user-guide/modules/channel/… – Elena Feb 6 '14 at 8:34
  • Since the current state of these fieldtypes is a bit 'lacking'. I would go for a stash list. Store each category item in the list, with it's brand included, then you can filter when showing the list. – GDmac Feb 6 '14 at 8:52
  • 1
    I'd check and see if P&T's Playa and Matrix aren't better suited to the job - just saying. – erwinheiser Feb 7 '14 at 13:14
0

I resolved using Matrix + Playa, although I'd have preferred to use native functions like Grid. Here's my code:

{exp:channel:entries channel="my_channel" dynamic="no"}

{catalogue search:brand="{segment_2}"}

{brand}

{brand_title}

{/brand}

{/catalogue}

{/exp:channel:entries}

Where {catalogue} is a Matrix field and {brand} is a Playa field that catch the data from the "brand channel". The dynamic="no" allows me to show only filtered entries in www.mysite.com/catalogue/(name of brand) based on {segment_2}, otherwise the list would remain blank.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.