# Blog template for scenario where only some articles are translated

**URL:** <https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882>\
**Category:** Questions\
**Tags:** v2\
**Created:** [November 28, 2016, 1:34pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882 "2016-11-28T13:34:37Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinthiemann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/martinthiemann/32/1981_2.png) [@martinthiemann](https://forum.getkirby.com/u/martinthiemann)\
**Post date:** [November 28, 2016, 1:34pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/1 "2016-11-28T13:34:37Z")

</div>

Hi there! I am a bit lost.  
What I like to achieve is sth I read a few times here but can’t find a concrete answer:

I have a multilingual page setup (en default, de). But only the blog section should behave differently. We will post some articles only in English, some only in German, and some will be translated.  
So /blog should only list English posts, /de/blog should only list German posts.

I found @texnixe ’s solution for this, but it seems outdated. I downloaded the latest starter kit. Since I am a php newbie, I would love to hear suggestions from you. Thanks in advance. – Martin

I guess the magic happens here:

Controller:

```
<?php
return function($site, $pages, $page) {

  $perpage = $page->perpage()->int();
  $articles = $page->children()
               ->visible()
               ->flip()
               ->paginate(($perpage >= 1)? $perpage : 5);

  return [
'articles' => $articles,
'pagination' => $articles->pagination()
  ];
};

```

blog template:

```
<header class="wrap">
  <?php
  if($pagination->page() == 1):
  ?>
  <?php endif ?>
  <hr />
</header>

<section class="wrap">
  <?php if($articles->count()): ?>
    <?php foreach($articles as $article): ?>

      <article class="article index">

        <header class="article-header">
          <h2 class="article-title">
            <a href="<?= $article->url() ?>"><?= $article->title()->html() ?></a>
          </h2>

          <p class="article-date"><?= $article->date('F jS, Y') ?></p>
        </header>

        <?php snippet('coverimage', $article) ?>

        <div class="text">
          <p>
            <?= $article->text()->kirbytext()->excerpt(50, 'words') ?>
            <a href="<?= $article->url() ?>" class="article-more">read more</a>
          </p>
        </div>

      </article>

      <hr />

    <?php endforeach ?>
  <?php else: ?>
    <p>This blog does not contain any articles yet.</p>
  <?php endif ?>
</section>

<?php snippet('pagination') ?> 

```

---

<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:** [November 28, 2016, 1:42pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/2 "2016-11-28T13:42:43Z")

</div>

You can filter your page collection like this:

```auto
<?php
$articles = $page->children()->visible()->filter(function($child) {
  return $child->content(site()->language()->code())->exists();
});

```

---

<div class="post-metadata">

**Author:** ![martinthiemann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/martinthiemann/32/1981_2.png) [@martinthiemann](https://forum.getkirby.com/u/martinthiemann)\
**Post date:** [November 28, 2016, 2:25pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/3 "2016-11-28T14:25:13Z")

</div>

Yay, that instantly worked! Thanks a lot. Will test further.  
Martin

---

<div class="post-metadata">

**Author:** ![martinthiemann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/martinthiemann/32/1981_2.png) [@martinthiemann](https://forum.getkirby.com/u/martinthiemann)\
**Post date:** [December 5, 2016, 11:14am UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/4 "2016-12-05T11:14:48Z")

</div>

Hi, again regarding this one.

Does it mean I only can create a German-only blog post (en is default lang) without the panel? Because when adding a German blog post via panel, a en text file is created in every case.

If this is the case, I wonder how I could filter blog post like “when “text” field is not empty”?

Thanks for your ideas! –Martin

---

<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:** [December 5, 2016, 11:34am UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/5 "2016-12-05T11:34:47Z")

</div>

You could check if the file exists and the field is empty:

```auto
$articles = $articles->filter(function($child) {
  return $child->content(site()->language()->code())->exists() && $child->content(site()->language()->code())->get('text')->isNotEmpty();
});

```

This might get a bit tricky with the pagination, I just had a strange behaviour in the langkit. Will check later. But you’ll probably have to use a custom page method to get that right.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [December 5, 2016, 5:13pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/6 "2016-12-05T17:13:04Z")

</div>

> [@martinthiemann](#):
>
> Does it mean I only can create a German-only blog post (en is default lang) without the panel?

I have downloaded the original Kirby Langkit version 2.4.0 and installed it on XAMPP with Windows.  
Then I have changed the default language to German and changed the German ‘url’ to ‘/de’ in the file `\site\config\config.php`.  
If I go to “`/panel/pages/blog/content/edit`”, I see this content file `article.en.txt` with the fields of the blueprint `default.yml`, because there is no content file `article.de.txt`. It is unimportant whether in my profile DE or EN is selected as language. Also, the language whose fields appear in the panel is not relevant to this behavior.

I think this is an error in the actual panel version. What do you think @texnixe?

@martinthiemann:  
So I have to answer your question with: yes!

---

<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:** [December 5, 2016, 6:11pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/7 "2016-12-05T18:11:53Z")

</div>

> [@anon77445132](#):
>
> I think this is an error in the actual panel version. What do you think @texnixe?

I’ll have to look into this. But I don’t quite see how it relates to @martinthiemann’s issue?

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [December 5, 2016, 6:19pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/8 "2016-12-05T18:19:36Z")

</div>

> [@texnixe](#):
>
> But I don’t quite see how it relates to @martinthiemann’s issue?

To simulate his problem, I only changed DE and EN related to the quoted problem description from the previous post, so we can use the default download as I sayed in my post.

I discovered this yesterday…

---

<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:** [December 5, 2016, 7:16pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/9 "2016-12-05T19:16:52Z")

</div>

@anon77445132: If you change the default language, you have to rename the text files if you want to use the panel. The panel always creates the textfile for the default language automatically.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [December 7, 2016, 4:41pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/10 "2016-12-07T16:41:57Z")

</div>

Sorry @texnixe, I think that was not the question of @martinthiemann. [quote=“martinthiemann, post:4, topic:5882”]  
Does it mean I only can create a German-only blog post (en is default lang) without the panel?  
[/quote]

---

<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:** [December 7, 2016, 6:28pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/11 "2016-12-07T18:28:12Z")

</div>

@anon77445132: As I said above, the panel **always** creates the textfile for the default language when you create a page in a non-default language. This was to confirm @martinthiemann’s question.

But that not really the important part here, the question is how to filter content to get only the content in a particular language, no matter in what language that content was created and to prevent the fallback to the default language.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:53pm UTC](https://forum.getkirby.com/t/blog-template-for-scenario-where-only-some-articles-are-translated/5882/12 "2025-02-06T16:53:10Z")

</div>


