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

#1

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);
0 Likes

#2

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

0 Likes

#3

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.

0 Likes

#4

Do you get different results if you

dump($excluded);

in the different languages?

0 Likes

#5

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.

0 Likes

#6

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?

0 Likes

#7

database

0 Likes

#8

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

0 Likes

#9

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

0 Likes

#10

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

0 Likes

#11

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

0 Likes

#12

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

0 Likes

#13

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.

0 Likes

#14

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

0 Likes

#15

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

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

#16

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.

0 Likes

#17

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?

0 Likes

#18

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?

0 Likes

#19

Nope. No cache enabled in development mode.

0 Likes

#20

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

0 Likes