I would like a clean and simple address for my blog posts without a folder structure.
Currently I have:
domain.tdl/home/my-blog-post
I would prefer:
domain.tdl/my-blog-post
How do I set up the blueprints / templates to avoid having ‘home’ show as a directory in the web address?
Close, but something is not quite right. The address part is working (domain.tdl/my-blog-post) but the request is being redirected to the error page. I’m using the page models method?
/site/models/article.php
<?php
class ArticlePage extends Page {
public function url($options = null): string {
return $this->slug();
}
}
/site/templates/home.php
<?php foreach ($page->children()->listed()->sortBy('date', 'desc') as $article): ?>
<a href="<?= $article->url() ?>"><?= $article->title() ?></a>
<?php endforeach ?>
This only works in conjunction with the routes, simply changing the url will indeed go to the error page.
Ah, apologies… now I understand, Its working now 
Can I use the same method with a tag in the URL?
For example:
domain.tdl/journal lists articles with the tag ‘journal’
A little stuck rendering posts with a tag of ‘journal’ using home:
Address: /home/post-1
Rewriten to: /post-1
Template: article.php
When I click on a tag, say ‘journal’ and render an address of /journal I get an error page (/site/template/default.php) instead of the home page.
I’ve added a route for journal but obviously going wrong somewhere:
/site/config/config.php
<?php
return [
'routes' => [
[
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('home/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
],
[
'pattern' => 'journal',
'action' => function ($tag) {
return page('home')->render([
'tag' => $tag
]);
}
]
]
];
/site/models/article.php
<?php
class ArticlePage extends Page {
public function url($options = null): string {
return $this->slug();
}
}
Well, the journal
route would have to come before (:any)
, because (:any)
already catches it, so no need for Kirby to try the next route, unless you specifically call the next route if you encounter an error in the first.