Hallo,
With the help of the plugin info about the contacts collection in the flex-objects description I created an own collection about Records.
Everything works fine except the search in the collection. The search is only on the name (naam) not the title (titel) or the box (doos).
My search criteria in the records.yaml file looks like:
search:
# Search options
options:
contains: 1
# Fields to be searched
fields:
- naam
- titel
- doos
I used the Collection template flex/contacts/collection/default.html.twig. The last lines I changed to:
<script>
var options = {
valueNames: [ 'naam','titel','doos']
};
var flexList = new List('flex-objects',options);
</script>
What I experienced:
I can only search on name not title or box;
The flex/contacts/collection/default.html.twig of the contacts example has two lines added at the beginning of the file. When I add those two lines in my twig file the collection doensât show a thing.
The two lines which are added are:
{%- set object_context = object ?? {} -%}
{%- set object_layout = object_context.layout ?? (âlist-â ~ layout) -%}
My questions are:
Have I executed the right steps?
What should I do to be able to search on all the three items (naam, titel, doos)?
Why gives the search no results when the two lines are added?
Is there a general recipe to make collections using flex-objects or should you follow the example steps of contacts in de plugin description?
With the limited knowledge of twig I am not able to solve this.
Thanks for giving me the answers.
By the way flex-object is a great extension to grav.
I found the solution. I typed the file object/default.html.twig completly over and skipped the lines which were irrelevant. I can now search on all items.
Sorry to bother you with my questions.
Hello, Iâm struggling with Flex Objects and it seems you achieved a result really similar to what I am thinking of.
Unfortunately, documentation still lacks some important parts and learning curve is really steep.
It would be of great help if you could share the whole code for the files involved!
Thank you!
First I made my own records.yaml file. Therefore I copied the contacts example and changed some data. I placed the .yaml file in user/blueprints/flex-objects. This is because after an upgrade of the plugin I lost my data.
I put the data file records.json (same as contacts.json) in user/data/flex-objects.
I put in the templates/flex/records folder 2 subfolders object and collection (just like the example of contacts) and copied the examples of contacts in these folders.
records/collection/default.html.twig changed the last lines in:
<script>
var options = {
valueNames: [ 'auteur', 'titel' , 'doos' ]
};
var flexList = new List('flex-objects', options);
records/object/default.html.twig and records/object/list-default.html.twig are here the same:
This actually helped a lot, thanks! The Plugin page covers areas Docs do not. Mixing the two was the key.
I will now keep experimenting with data presentation, thank you!
Thanks a lot! I have made some progress following this solution.
I have a question. Did you have to update the user/plugins/flex-objects/flex-objects.yaml file? The flex-objects.yaml file contains this configuration:
Hi! No update needed on user/plugins/flex-objects/flex-objects.yaml, did you place the Flex Object blueprint file containing the definitions in the right folder? Is the blueprint correctly filled?
I remeber starting with the duplication of the âcontactsâ blueprint and adding functionalities from that, following the documentation here.