Is there a way to get filterBy('template', 'mytemplate') work on a multilang site?

Is there a way to get filterBy('template', 'mytemplate') work on a multilang site? It works fine on the default language but not the other languages.

This is the current code in my controller:

// Exclude protected pages from the search:
$excluded = $site->index()->filterBy('template', 'in', ['single.database', 'list.database']);

// Fetch data from query string, searching the whole site:
$result = $site->search($query, $settings)->visible()->not($excluded);

What exactly doesn’t work as expected? What results do you expect and what do you get? FilterBy() should work as expected.

I want to exclude all pages using a specific template from the search result. It works as expected on my default language, that is, no pages with that template are displayed.

But when I’m searching from another language the search result contains pages with that template.

Do you get different results if you


in the different languages?

The var_dump on my default lang looks like:

object(Children)#185 (2) { [0]=> string(12) "databas/demo" [1]=> string(18) "databas/demo/demo2" }

And the other lang:

object(Children)#450 (2) { [0]=> string(12) "databas/demo" [1]=> string(18) "databas/demo/demo2" }

Notice: Everything else work as expected with my multilang setup.

Ok, then the exclude thingy seems to work as expected. Hm, that’s really strange and I can’t reproduce this in a starterkit. Could you post a screenshot of your databas folder with all the files in it?


Thank you, that looks ok.And which page appears in the search results that shouldn’t appear there?

In this example both demo and demo2 appear in the search result. But they have the template single.database and should not appear.

Could you test if the problem persists if you remove the dots from your template names?

I got the same result when removed the dots and replaced them with underscore.

Could the problem be in the not() function when having a multilang site?

Hm, what Kirby version are you using? Could you provide more information about your environment? I currently have no idea anymore what might be causing this.

As I said, I can’t reproduce this at all.

Sure. I’m running 2.5.7, both kirby and panel. My local environment is in MAMP Pro using PHP 7.1.12.

And leaving the search aside, are the pages excluded if you do

$excluded = $site->index()->filterBy('template', 'in', ['single.database', 'list.database']);

This is my default lang (sv):

The last row (databas/demo databas/demo/demo2) becomes the same in both langs. Here I’m using a foreach loop to print it out.

This is my second lang (en):

As you can se there are some different output between index 25 - 27.

I see. I have no ideas anymore and can’t reproduce this with 2.5.7 either. Can you reproduce this in a fresh starterkit? All that I can offer now is to have a look into your project if you want to send me a zip.

Edit: You don’t have caching enabled, do you?

I’m very grateful for your help. I can try digging a little deeper into it before sending over a zip.

What I want to do is:
I have a section on the page which is protected with a login. No pages which are protected shall be displayed in the search. It’s a minor issue because I have a route redirect to the error page if the visitor trying to go to a protected page and not are logged in. But still, it is a bad user experience to show hidden/protected pages in the search.

Maybe you know another way around to hide them?

Nope. No cache enabled in development mode.

I got the same result on another project running with Kirby v2.5.8.