Subpage: file name

Hello,

try to create a blog with kirby but i don’t understand how change the subpages file names automatic (filename = template).

To have two different templates one for the news overview and one for the full article.

greetings perry.

Let’s say your full articles have the filename “article.txt” and you have a template “article.php” to display a single article.

To show a short version of the article on the news overview page, you don’t have to change the filenames of the single articles. You can call the child pages in your news.php template like this:

<?php
$articles = page('news')->children()->visible();
foreach($articles as $article) {
  //do stuff
}
?>

I hope, this answers your question?

hello texnixe,

thank you for answering,

how to change the template when the user clicked on ‘read more…’ ?

<?php foreach($page->children()->visible()->flip() as $article): ?>

      <article>
        <h1><?php echo $article->title()->html() ?></h1>
        <p><?php echo $article->text()->excerpt(300) ?></p>
        <a href="<?php echo $article->url() ?>">Read more…</a>
      </article>

<?php endforeach ?>

You don’t need to change the template, if the user clicks on “Read more”, Kirby will automatically load the template with the same name as the filename of the article; if a template with this filename does not exist, Kirby will use the default.php template.

To make this clearer: You should have the following structure/files:

/blog
blog.txt
  /article-one
    article.txt
  /article-two
    article.txt

Then you need two templates: blog.php, which lists all articles, and article.php, which shows the single articles when a user clicks on the “Read more” link.

Your code above would go into blog.php …

You may want to check out the Baseblog Kirby theme for an example of how this works …

When i create a new page the filename is allways default.txt,
where can this be changed?

When you create a page in the panel, you need to choose the right page template. You might have to change the settings of the parent page blueprint, e.g. in your blog.php blueprint, add these settings:

title: Blog
pages:
  template:
    - article
files: true
fields:
  ...

Then each time you create a new post as child of blog, the file is called article.txt.

If you want to use different template for different kind of articles, e.g. an image post and a video post, you can add more templates to the list and then select the right one on page creation.

My ‘programm’ blue print:

title: Programm
pages:
  template:
    - article
files: true

the file structure:

/5-programm
programm.de.txt
/1-article-0/default.de.txt

when i add a new ‘programm’ subpage i can`t change the template
in the pull down.

Have you created an article.php blueprint, so that this can be loaded?

Okay sorry now i understand
if i want change the template for each subpage level
i must have for each a blue print file to set the filename.

Yes, exactly, you need a blueprint for every template, otherwise you cannot select it in the panel.

1 Like

Thanks for your help