Tag template/route is the same as home

We are trying to add specific code that shows up on the homepage, and doesn’t show up for tag: routes. As it stands, any tag routes use the home.php template.

We tried to add if ($page->isHomePage()): with no luck.

Homepage: http://jfi-pw.partnerandpartners.com/
Tag Page: http://jfi-pw.partnerandpartners.com/tag:staff+picks

Here’s the routes section of the config:

'routes' => [
	'pattern' => '(:any)/(:any)/image.png',
	'action'  => function ($base1, $base2) {
		$page = page($base1.'/'.$base2);
			if (!$page) {
				return site()->visit(site()->errorPage());
		if ($page->file('image.png')) return go($page->file('image.png')->url());
		if ($page->hasImages()) return go($page->image()->url());
		return go(site()->url().'/assets/images/pw-icon.png');

Site.php Controller:


return function($site, $pages, $page, $args) {
	$collection = new Pages();

  if ($page->isHomePage()):
    $collection = $site->index()->listed()->filterBy('template','article');
    $collection = $collection->sortBy('date', 'desc');

  elseif ($page->template() == 'author'):
    $collection = $site->index()->listed()->filterBy('authors', '*=', $page->autoid());
    $collection = $page->children()->listed()->sortBy('date', 'desc');

  if ($page->title() !== "search") {
    $articles = $collection->sortBy('date', 'desc');

  if($tag = urldecode(param('tag'))) {
    $articles = $site->index()->listed()->filterBy('tags', $tag, ',')->sortBy('date', 'desc', 'time', 'asc')->paginate(10);
  } else {
    $articles = $collection->paginate(10);

  $pagination = $articles->pagination();

  // Get the authors
  $authors = [];
  foreach($page->authors()->split() as $author):
    $authors[] = page('authors')->children()->findBy('autoid', $author);

  $tag = ucwords(kirby()->request()->params()->tag());
  if ($tag != "") {
  	$top_title = "<span class='tag-title'>↳&nbsp;{$tag}</span>";
  } elseif ($page->template() == "search") {
    $top_title = "Results for&nbsp;'" . $query . "'";
  } elseif ($page->template() == "category") {
    $top_title = "↳&nbsp;" . $page->title();
  } elseif ($page->template() == "author") {
    $top_title = "➔&nbsp;" . $page->title();
  } else {
    $top_title = "Phenomenal World";

  return compact('authors', 'articles', 'pagination', 'top_title');

Hm, I don’t really understand how the route relates the rest of your code.

Which part is that?

I’m trying to add a block of code

      <?php foreach(page('letters')->children()->published()->sortBy('date', 'desc')->limit(5) as $letter): ?>
        <a href="<?= $letter->url() ?>">
          <?= $letter->title() ?>
      <?php endforeach ?>

and have it only show up on the homepage. But both the root / and /tag:[tagname] pages share the home.php template and I don’t understand why.

/tag:tagname is not a page (but why does it not have a normal Url when it is a page?), but a parameter and if you append this parameter to the home page, the home page template will be used.

If this is not intended, you would have to point your tags somewhere else, or use additional logic in your if statement, e.g.

if ($page->isHomePage() && empty(params())) {
  // do stuff
1 Like

That worked, thank you!!