Custom collection method not working

I’m trying to register a custom collection method in a site-specific plugin.

I’ve put this in my index.php before the $kirby->render() call:

use Kirby\Cms\App;

App::plugin('site/collection-methods', [
    'collectionMethods' => [
        'myCustomMethod' => function () {
            return 'test';
        },
    ],
]);

Then I’m trying to use that method in a template:

var_dump($page->siblings()->myCustomMethod());

This always prints NULL.

Any ideas what I’m doing wrong? How can I debug this? Trying to use a collection method that doesn’t exist doesn’t throw an error – instead of providing an error message, this prints null as well:

var_dump($page->siblings()->dsabniangzdscyxncy());

Not sure about that API design, but anyway. How can I find out why my collection method is not working?

Plugins have to go into the site/plugins folder, each plugin as a separate folder with it’s own index.php

@texnixe According to the documentation and my tests, this isn’t the case. All that’s required is the App::plugin call, which I can put anywhere I want as long as I make sure the file is included.

I found out why it’s not working, though – the App::plugin call has to come before creating the kirby object with new App(). Then it works fine.

I don’t want to put my site-specific plugins there, because plugins installed via Composer are put in that folder, so its ignored in my .gitignore. I don’t want to have to adjust my gitignore every time I add a custom plugin. Also, I want to have some separation between community plugins and my own site-specific plugins. Kirby doesn’t support this (without an additional plugin), so for now I’ve put the App::plugin call in my index.php. I’m going to move those to a custom folder as soon as it’s working how I want it to, though.