Pseudo forum with tabs in panel

I would like to display a pseudo forum, that is basically a blog with comments, from a tab in the panel. But how do I access the pages with the entries in a list template? This is what I like to do:

<?php foreach($site->forum()->listed() as $forumpost): ?>

, but of course Kirby doesn’t know "forum()

Also the forums posts, that I created for testing, don’t get put into the content/5_forum, but just into the content folder.

I could do:

<?php foreach($site->children()->listed() as $forumpost): ?>

But that shows me of course all the pages.

I did this:


        <?php $item = $site->find('forum')->children()->listed();?>
        <?php foreach($item as $forumpost): ?>

          <article>
            <time class="date"><?= $forumpost->date()->toDate('%d.%m.%Y') ?></time>
            <h3><?= $forumpost->title()->html() ?></h3>
            <p><?= $forumpost->eintrag()->text()->excerpt(20)->html() ?></p>
            <a class="more-link" href="<?= $forumpost->url() ?>">Mehr &raquo;</a>
        </article>

    <?php endforeach ?>

which does give me a list of entries (hurray), but Kirby puts the entries/ pages in the top level of the content folder, not into content/5_forum .

So, I did something wrong with the blueprints?

This is the part in my site blueprint:

      label: Forum
      icon: document
      type: pages

      sections:
        drafts:
          headline: Entwurf
          type: pages
          status: draft
          templates: forumpost
      
        published:
          headline: Im Forum
          type: pages
          status: listed
          templates: forumpost

What is this supposed to be? Seems incomplete?

Oh I missed the tab while copying the thing. It is

 forum:
      label: Forum
      icon: document
      type: pages

      sections:
        drafts:
          headline: Entwurf
          type: pages
          status: draft
          templates: forumpost
      
        published:
          headline: Im Forum
          type: pages
          status: listed
          templates: forumpost

Still the pages don’t come into their folder in the content folder, but just into content. If I put them manually there, it works.

A tab doesn’t have a type, so please remove that. It is just a layout element, you cannot do anything with it.

It looks as if you want to store the pages you create via the two sections in a parent called forum. But for this purpose you have to define the parent property in the two sections:

    sections:
        drafts:
          headline: Entwurf
          type: pages
          status: draft
          parent: site.find('forum')
          templates: forumpost
      
        published:
          headline: Im Forum
          type: pages
          status: listed
          parent: site.find('forum')
          templates: forumpost

Oh! I saw that in the docs, but I thought, since the site doesn’t have a parent its the wrong thing. Now I can’t find it anymore.

Anyway - thank you very much!!!

No, the site doesn’t have a parent, but if you don’t specify a parent and you are in the site.yml blueprint, the site becomes the parent of a page you create in a section.

Yeah, now I got it.

But another stupid question, that I probably asked before, but can’t find the answer to.

I have a page called “forum” in the pages section of the site in the panel. I would like to hide it there. If I go read: false in the options for forum.yml, the pages doesn’t get displayed in the pages section in the panel, which is finde, but then I can’t create new pages, which seems kind of logical.

But oh the other hand, if I let the page “forum” appear in the panel, then there would be no need for a tab.

So, How can I go like “visiblity:hidden” for that page (forum) in the panel?

You can filter that page section by template, so only list templates that don’t include the template the forum page uses. Unfortunately, we don’t have a “not template X” feature yet, so it only works by explicitly listing all other templates.

Ok, maybe I try a workaround.

How can I now display the author of a post on the listing page (‘forum’).

This is the template

 <?php $item = $site->find('forum')->children()->listed();?>
        <?php foreach($item as $forumpost): ?>

            <article class="forum-posts-as-list">
                <time class="date"><?= $forumpost->date()->toDate('%d.%m.%Y') ?></time>
                <p><?= $forumpost->author()->username()->html() ?></p>

                <h3><?= $forumpost->title()->html() ?></h3>
                <p><?= $forumpost->eintrag()->text()->excerpt(100)->html() ?></p>
                <a class="more-forum-link" href="<?= $forumpost->url() ?>">Mehr &raquo;</a>
            </article>

        <?php endforeach ?>

But this gives me just a strange set of characters (like “- cuSHMMxg”).

I guess <?= $forumpost->author()->username()->html() ?> is somehow wrong.

In the template for the posts code snippet this from the docs works just fine:

<?php if($author = $page->author()->toUser()): ?> <?= $author->name() ?><?php endif ?>

Oh, this seems to be the right path:

<?php if($user = $forumpost->author()->toUser()): ?>
 <p> <?= $user->username() ?></p>
<?php endif ?>