# Display snippet in subdirectory

**URL:** <https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 13, 2019, 7:31pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365 "2019-03-13T19:31:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenney](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kenney/32/1322_2.png) [@Kenney](https://forum.getkirby.com/u/Kenney)\
**Post date:** [March 13, 2019, 7:31pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/1 "2019-03-13T19:31:45Z")

</div>

I’d like to display a snippet outside of Kirby’s templates in the header of PHP forum software which resides in a subdirectory on the server (Kirby in the root).

Here’s what I’ve got so far;

```
define('DS', DIRECTORY_SEPARATOR);

require( __DIR__. DS . '../kirby' . DS . 'bootstrap.php');

$kirby = kirby();

$kirby->urls->index = 'https://' . $_SERVER['SERVER_NAME'];
$kirby->launch();

snippet('header');

```

Unfortunately, this immediately shows an error when the snippet tries to display “$site-\>title()”. I’m assuming this is because it can’t find the site content or the base path of Kirby might be the subdirectory of the forum instead of the server root?

_Just for clarification;_  
Kirby is in the root of the server, the forum software in /forums/.

---

<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:** [March 13, 2019, 7:56pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/2 "2019-03-13T19:56:19Z")

</div>

You would have to pass your variables to the snippet:

```auto
snippet('header', ['site' => $kirby->site()]);

```

---

<div class="post-metadata">

**Author:** ![Kenney](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kenney/32/1322_2.png) [@Kenney](https://forum.getkirby.com/u/Kenney)\
**Post date:** [March 13, 2019, 8:30pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/3 "2019-03-13T20:30:00Z")

</div>

The error remains unfortunately, here’s the error in question;

 ![2019-03-13_21-28-41](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/2/28c68e8712181e51feb674ce634c81bc916f9d2d.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:** [March 13, 2019, 8:33pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/4 "2019-03-13T20:33:41Z")

</div>

Does the error refer to the `$site` or the `$page` variable?

---

<div class="post-metadata">

**Author:** ![Kenney](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kenney/32/1322_2.png) [@Kenney](https://forum.getkirby.com/u/Kenney)\
**Post date:** [March 13, 2019, 8:46pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/5 "2019-03-13T20:46:45Z")

</div>

I removed the last bit ($page-\>title()-\>html()) and it continues up to the next reference to $page so seems like $page is the issue, how would I fix that? Is there somehow to “fake” a page object and fill in the details?

---

<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:** [March 13, 2019, 8:50pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/6 "2019-03-13T20:50:33Z")

</div>

You could just pass it `page()`, which will the refer to the home page (option 1); or you use an if statement in your header, that only tries to output the page title if $page is defined, which probably makes more sense.

Option 1:

```auto
snippet('header', ['site' => $kirby->site(), 'page' => page()]);

```

Option 2

Do not send send the `$page` variable via the snippet and in your header:

```auto
<title><?= $site->title()->html() ?> | <?= isset($page)? $page->title()->html(): 'Forum' ?></title>

```

---

<div class="post-metadata">

**Author:** ![Kenney](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kenney/32/1322_2.png) [@Kenney](https://forum.getkirby.com/u/Kenney)\
**Post date:** [March 13, 2019, 9:06pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/7 "2019-03-13T21:06:09Z")

</div>

That’s fantastic, working perfectly now! Thanks for the help, hopefully others will find this useful too.

---

<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, 5:23pm UTC](https://forum.getkirby.com/t/display-snippet-in-subdirectory/13365/8 "2025-02-06T17:23:17Z")

</div>


