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

**URL:** <https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 8, 2018, 12:16pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656 "2018-02-08T12:16:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 12:16pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/1 "2018-02-08T12:16:58Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 12:31pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/2 "2018-02-08T12:31:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 12:37pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/3 "2018-02-08T12:37:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 12:40pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/4 "2018-02-08T12:40:14Z")

</div>

Do you get different results if you

```auto
dump($excluded);

```

in the different languages?

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 12:46pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/5 "2018-02-08T12:46:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 12:50pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/6 "2018-02-08T12:50:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 12:52pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/7 "2018-02-08T12:52:44Z")

</div>

![database](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/6/68f9407f7ce687313f1ce03b45f8462bc49a2237.png)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 12:59pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/8 "2018-02-08T12:59:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:01pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/9 "2018-02-08T13:01:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 1:02pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/10 "2018-02-08T13:02:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:05pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/11 "2018-02-08T13:05:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:15pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/12 "2018-02-08T13:15:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 1:15pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/13 "2018-02-08T13:15:51Z")

</div>

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.

> [@kaloja](#):
>
> Could the problem be in the not() function when having a multilang site?

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

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:16pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/14 "2018-02-08T13:16:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 1:18pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/15 "2018-02-08T13:18:40Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:29pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/16 "2018-02-08T13:29:22Z")

</div>

This is my default lang (sv):

 ![swedish](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/4/4c5142af1ed850e5b95355c9b5ba625265518f54.png)

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

 ![english](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/f/f90d123e736ace596e14829c714c34dd83636018.png)

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 8, 2018, 1:39pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/17 "2018-02-08T13:39:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:46pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/18 "2018-02-08T13:46:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:47pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/19 "2018-02-08T13:47:11Z")

</div>

Nope. No cache enabled in development mode.

---

<div class="post-metadata">

**Author:** ![kaloja](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kaloja/32/3470_2.png) [@kaloja](https://forum.getkirby.com/u/kaloja)\
**Post date:** [February 8, 2018, 1:58pm UTC](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656/20 "2018-02-08T13:58:16Z")

</div>

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

[Next page](https://forum.getkirby.com/t/is-there-a-way-to-get-filterby-template-mytemplate-work-on-a-multilang-site/9656.md?page=2)
