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.

1 Like

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.

3 Likes

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:

enabled: true

built_in_css: true
extra_admin_twig_path: 'theme://admin/templates'
admin_list:
  per_page: 15
  order:
    by: updated_timestamp
    dir: desc

directories:
  - 'blueprints://flex-objects/pages.yaml'
  - 'blueprints://flex-objects/user-accounts.yaml'
  - 'blueprints://flex-objects/user-groups.yaml'

Did you edit this file or you extended the file? Either way how did you do it so that the records directory would appear in the admin panel?

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.

1 Like

Thanks @phmg701 ! I had a bit of a confusion back then but it’s all good now. I followed the “contacts” example as suggested and it worked!