Using Flex-objects creating an own collection

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:

  1. I can only search on name not title or box;

  2. 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:

  1. Have I executed the right steps?
  2. What should I do to be able to search on all the three items (naam, titel, doos)?
  3. Why gives the search no results when the two lines are added?
  4. 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.

1 Like

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!

Hallo @phmg701, I am not realy an expert but with an example and trial and error I succeeded to make my own collection. I used the description of the plugin see: GitHub - trilbymedia/grav-plugin-flex-objects: Powerful and supremely flexible object support for Grav.

  • 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 created an own theme inhereted from Quark (Customization | Grav Documentation)

  • 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:

<div class="entry-details">
{% if object.auteur %}
  <p  class="auteur">{{ object.auteur }}</p>
{% endif %}   
{% if object.titel %}
   <p class="titel">{{ object.titel }}</p>
{% endif %}
{% if object.doos %}
   <p class="doos">{{ object.doos }}</p>
{% endif %}

Hopefully this will help a little. But as I said, I am not an expert.

1 Like

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!