-
-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.x] Dictionary tag #10885
[5.x] Dictionary tag #10885
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to get all the data you can add supplement_data similar to search results
Do we think this would be a performance concern? I don't think so. Might as well just include the data all the time. It's already just sitting there.
The reason we do it in search is because we need to actually do separate lookups etc.
Sure, easily changed. |
This method gets an array of Item instances that would be used for each option. To make it backwards compatible, a method is added to the abstract class. It's not performant, but it works. The BasicDictionary class overrides it to make it performant. If someone is making a dictionary that extends the base class, they don't have to override it, but they can if they want to improve the performance. This is all done because ->options() would get the options, then calling ->get() is happening for each option, which would end up getting all the options for each one. In the case of the file dictionary for example, this means the file is read and parsed for each line in the file.
This was a bit out of scope for the tag, but I added a new method to the dictionary class to get the options. The way you had it:
i.e. When listing the countries, it would re-read the array 250 times, one for each country. This wasn't your fault as there wasn't an alternative for you. Now, it'll get the options just once. |
Yeah I had noticed that and had considered adding an all() or something to dictionary but didn’t want to push the PR too far! |
This PR adds a
{{ dictionary }}
tag to Antlers, allowing you to use dictionaries outside the field type.Usage:
{{ dictionary:countries }}{{ label }} {{ value }}{{ /dictionary:countries }}
or
{{ dictionary handle="countries" }}{{ label }} {{ value }}{{ /dictionary}}
It also gets any ‘extra’ data:
{{ dictionary handle="countries" }}{{ emoji }} {{ value }}{{ /dictionary}}
Searching:
{{ dictionary:countries search="Aus" }}{{ label }} {{ value }}{{ /dictionary:countries }}
Passing config:
Any params passed that arent handle or search will be passed as config... eg
{{ dictionary:countries emojis="false" }}{{ label }} {{ value }}{{ /dictionary:countries }}
conditions, pagination, chunking and limiting:
It supports conditions, pagination, chunking and limiting eg
{{ dictionary:countries iso2:is="AUS" paginate="4" }}{{ label }} {{ value }}{{ /dictionary:countries }}
query scopes
You can also use query scopes:
{{ dictionary:countries query_scope="my_scope" }}{{ label }} {{ value }}{{ /dictionary:countries }}
Files:
Where this gets really powerful is pulling in arbitrary files and being able to filter, paginate and output them:
{{ dictionary:file filename="products.json" label="Name" value="Code" paginate="4" }}
Note:
Under the hood its using an Item query builder to allow filtering, ordering etc.
Closes statamic/ideas#1214.