I have a grid field like this:
File - Text field - Relationship field
Where the file is a document, the text field is the title and the relationship field is the argument.
I would like to output the list of files like this:
Argument 1 File 1 File 3 File 6
Argument 2 File 2 File 4 File 5
And so on, therefore grouped by the relationship field.
Now I have something like
{grid}
<li><a href="http://{grid:file}"> {grid:text_field} </a> - {grid:relationship}{grid:relationship:title}{/grid:relationship}</li>
{/grid}That shows me:
File 1 - Argument 1 File 2 - Argument 2 File 3 - Argument 1 File 4 - Argument 2 File 5 - Argument 2 File 6 - Argument 1
How can I output the items by grouping them by argument? It means that the relationship field must shows only one time per type, and create a list for every type.
I mean a query which is custom..😉
When you create channel:entries tag pairs in templates what you are really doing is writing simplified SQL statements (queries) which EE uses to go to the database to fetch content.
Your use case isn’t within the current functionality of the relationship tag, so I’m suggesting you can use the Query module to write your own SQL statement to achieve the results you are looking for.
I resolved using Matrix and Playa. I used those because of the Playa parents tag. I could not use the native features of Grid and Relationship because, according to the documentation, “Currently it is not possible to get the parents of a relationship field that is inside of a Grid field”.
The code is:
{exp:channel:entries channel="arguments"}
{title}
{exp:playa:parents channel="documents" var_prefix="doc"}
{doc:matrix_field search:relationship="[{entry_id}]"}
<li><a href="http://{file}">{text_field}</a></li>
{/doc:matrix_field}
{/exp:playa:parents}
{/exp:channel:entries}Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.