# Comments Plugin for Kirby v3

**URL:** <https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299>\
**Category:** Plugins\
**Tags:** idea\
**Created:** [March 10, 2019, 1:07am UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299 "2019-03-10T01:07:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![RastaTux](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@RastaTux](https://forum.getkirby.com/u/RastaTux)\
**Post date:** [March 10, 2019, 1:07am UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/1 "2019-03-10T01:07:00Z")

</div>

Hey there!

I used [GitHub - Addpixel/KirbyComments: [Kirby 2] File-based comments stored as subpages for the Kirby CMS.](https://github.com/Addpixel/KirbyComments), the plugin of Florian in many websites until today. The new Kirby v3 looks gorgeous to me and I installed it. After a not-that-easy process, i got it working - besides the Comments Plugin. It not just doesn’t work, it even breaks the translation stuff.

Does anybody have an idea what’s the main problem of that plugin or can provide me with an actually working Comments Plugin for Kirby v3? Maybe @florianpircher can help me here? 🙂

Greetings,  
RastaTux

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [March 10, 2019, 8:25am UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/2 "2019-03-10T08:25:03Z")

</div>

The way plugins work for Kirby 3 is completely different to Kirby 2, so plugins need updating before they will work. You would need to wait for Florian to update it, or have a go your self, but it is a complex plugin so that may take a while.

---

<div class="post-metadata">

**Author:** ![florianpircher](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/florianpircher/32/4069_2.png) [@florianpircher](https://forum.getkirby.com/u/florianpircher)\
**Post date:** [March 10, 2019, 9:00am UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/3 "2019-03-10T09:00:18Z")

</div>

I have look into updating the plugin for Kirby 3, but had to conclude that updating the plugin would be more work than I am willing to put into the project. The plugin API has changed significantly with Kirby 3. Updating the plugin with all of its functions and options for the new API would require a complete rewrite of the software and its documentation.

Updating just the core functionality would actually be doable within a reasonable timespan, but then I would have to remove many features and options that are more difficult to translate to the new Kirby 3 architecture. If you are familiar with PHP and the new plugin API, you can look at _comments.php_ of the plugin and try to update only the parts that you need and delete the rest. I am happy to help if you have any questions about the internals of the plugin.

Because comments are saved as subpages, you can write your own snippet for rendering comments. That way you don’t loose the existing comments on your page.

---

<div class="post-metadata">

**Author:** ![RastaTux](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@RastaTux](https://forum.getkirby.com/u/RastaTux)\
**Post date:** [March 12, 2019, 11:28pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/4 "2019-03-12T23:28:41Z")

</div>

@florianpircher Ugh, yeah I thought so… I’m familiar with PHP, but neither with the new plugin API, nor the old one… But maybe i’ll try to play with it a bit… Thanks for offering your help!

---

<div class="post-metadata">

**Author:** ![RastaTux](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@RastaTux](https://forum.getkirby.com/u/RastaTux)\
**Post date:** [April 29, 2019, 11:35am UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/5 "2019-04-29T11:35:39Z")

</div>

Hey! To get my comments working in Kirby v3 I changed the code by @florianpircher, so the basics work for me now in v3. Feel free to commit merges!

> **[Jonas Marx / KirbyComments](https://gitlab.com/rastatux/kirbycomments)**
>
> File-based comments stored as subpages for the Kirby CMS - copied from Addpixel and made working on Kirby v3.

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 10, 2019, 6:56pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/6 "2019-05-10T18:56:31Z")

</div>

I have a few questions about getting this to work on Kirby 3.

1. plugins/kirbycomments: The instructions say to add this into the plugins directory, but Kirby 3 doesn’t natively come with a plugins directory. Will adding a directory /site/plugins actually work when adding the ‘kirbycomments’ directory into ‘/site/plugins’?
2. Where should the following files be placed in a Kirby 3 install: index.php, package.json

I think that is about it for now.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [May 10, 2019, 7:14pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/7 "2019-05-10T19:14:16Z")

</div>

Yes that will work. Kirby does not ship with any plugins, but it’s fine to manually create the folder and manually install plugins into it. The best way is to use composer, but this particualar plugin does not seem to be up for that, yet.

According to the read me, the downloaded files should go in…

```auto
site/plugins/kirbycomments/

```

So that everything goes in that folder, don’t put it in a sub folder.

```auto
site/plugins/kirbycomments/index.php
site/plugins/kirbycomments/package.json
... etc

```

Hope that helps.

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 11, 2019, 3:34pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/8 "2019-05-11T15:34:18Z")

</div>

Thanks @jimbobrjames – this does get the field to render, and the “preview” to render, but when submitting the comment I get an error. The result of which is here – It seems to be unable to create the comment file. I am wondering if it has to do with one of two issues:

1. It’s unable to access the YML file because it’s currently in the “plugins” directory (see screengrab).
2. There is some inability to the plugin to write to the appropriate content directory? Perhaps I have to update the path reference or give the plugin some write permission?

Thanks of course for any help.

Screengrab of my directory structure and of the error.

charles

 ![46%20AM](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/0/034a9b5d2ca7449ded1bd6a1cfb5247a898bd6b8.png)

 ![46%20AM](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/e/e91fdd3692270f936c6406e8b1bdffbd6c5611d9.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:** [May 11, 2019, 3:50pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/9 "2019-05-11T15:50:03Z")

</div>

Hm, looks like `$comments_page` is not created in the first step. The `yaml` file is not important in this context. Can the Panel write to the content folder?

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 11, 2019, 4:04pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/10 "2019-05-11T16:04:52Z")

</div>

Hi @texnixe – if by asking “Can the Panel write to the content folder?” meaning does the panel allow me to publish, it does. You can see where I am with things here if that’s helpful – [http://lostarts.xyz/craighton-berman/critique-1](http://lostarts.xyz/craighton-berman/critique-1)

This is the URL that produces the error in the example above, after fully submitting the comment.

---

<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:** [May 11, 2019, 4:22pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/11 "2019-05-11T16:22:39Z")

</div>

Hm, I don’t see how that error message is related to the comments page? The error I see there is caused by calling the `avatar()` method on a user when there is no user… There should be two if statements here:

```auto
<?php if($user = $kirby->user('someuser')) && $avatar = $user->avatar()): ?>
<!-- rest of code -->
<?php endif ?>

```

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 11, 2019, 4:38pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/12 "2019-05-11T16:38:38Z")

</div>

Hi @texnixe thanks for digging in. I started investigating before you added the code block above. Is that code block in reference to the comments page ($comments\_page) or is this related to the page causing the error “critique.php” (the template for this page)?

btw: I commented out much of the code in my critique.php, including my previous call to $avatar and user, and I’m still recieving the same error… hence the clarifying question above.

Thanks again!

---

<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:** [May 11, 2019, 4:41pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/13 "2019-05-11T16:41:26Z")

</div>

As indicated by the error message, that code comes from the `critique.php` template.

You can’t use HTML comments to comment out PHP, they have no effect at all… and the error is therefore still there.

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 11, 2019, 4:52pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/14 "2019-05-11T16:52:32Z")

</div>

Oy! #learning 🙂

Thanks @texnixe I’ll keep trying to figure this out…

---

<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:** [May 11, 2019, 4:53pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/15 "2019-05-11T16:53:59Z")

</div>

You are welcome 🙂. We are here…

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 11, 2019, 6:03pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/16 "2019-05-11T18:03:47Z")

</div>

So I’ve gone back and done a couple of things:

Per @texnixe comments I’ve gone through the resulting error (same as the screenshot above), as well as completely deleted majority of the contents of my critique.php template so the only thing that renders is the Header and Footer snippet along with the snippet for Comments.

Unfortunately I get the same error, and so it leads me to wonder, @texnixe are you seeing a different error than what I shared above?

Also in that screenshot error message it’s indicating the error is coming from:  
/nfs/c01/h06/mnt/6643/domains/lostarts.xyz/html/site/plugins/kirbycomments/plugin/Comments.php

So perhaps we’re seeing different issues?

---

<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:** [May 11, 2019, 6:06pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/17 "2019-05-11T18:06:48Z")

</div>

No, after the form was online I filled in the form and tried to submit, which then resulted in the same error message your originally posted above.

Somehow the parent folder is not created (the plugin should actually make sure there is a `$comments_page` before calling the `createChild()` method, but doesn’t. That would at least prevent the error.

Edit:

Ok, I had a closer look at the plugin code and there are at least three issues:

1. It doesn’t authenticate before trying to create the `$comments_page` page.
2. The code for creating the page is not correct, either (that is still Kirby 2 code, I think)
3. It doesn’t check if the parent page was successfully created before trying to create the comment children

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 11, 2019, 6:43pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/18 "2019-05-11T18:43:32Z")

</div>

Ha! I might have stumbled (though much more clumbsily) into a similar realization. I manually created a “comments” directory in the ‘content//’ directory and the comments stuck and I didn’t get the error (which I believe pertains to your points #1 and #2 above).

@RastaTux any thoughts based on your updating of the plugin?

Or any suggestions for another commenting option? Ideally something as simple as this one 🙂

---

<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:** [May 11, 2019, 6:47pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/19 "2019-05-11T18:47:33Z")

</div>

Well, those errors above can be fixed like this:

```auto
			// No comment was posted on `$this->page` yet; create comments page
			try {
				kirby()->impersonate('kirby');
				$dirname = Comments::option('pages.comments.dirname');
				$template = Comments::option('pages.comments.template');
				$comments_page = $this->page->createChild([
					$dirname,
					$template,
					'content' => [
						'title' => Comments::invokeHook('decide-comments-page-title', array($this->page)),
						'date' => $now->format('Y-m-d H:i:s')
					]
				]);
			} catch (Exception $e) {
				$this->status = new CommentsStatus(200, $e);
				return $this->status;
			}

```

And then before calling the second `createChild()` method for the subpages, add an if statement if the parent exists.

```auto
			// Save comment as page
				if ($comments_page) {
						kirby()->impersonate('kirby');
						$comment_page = $comments_page->createChild([
					  	    'slug' => $dirname,
						    'template' => $template,
						    'content' => $contents
						]);
						$comment_page->publish();
				}

```

---

<div class="post-metadata">

**Author:** ![cadler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cadler/32/5744_2.png) [@cadler](https://forum.getkirby.com/u/cadler)\
**Post date:** [May 11, 2019, 7:52pm UTC](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299/20 "2019-05-11T19:52:38Z")

</div>

I see what you’re doing here… cool. So I’ve gotten this input as you’ve suggested, but a new error has unfolded on line 495 below. Error and code…

Error message:

```
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /nfs/c01/h06/mnt/6643/domains/lostarts.xyz/html/site/plugins/kirbycomments/plugin/Comments.php on line 495

```

Code below:

```
/**
 * `true` iff no comment is managed by this `Comments` instance.
 *
 * @return bool
 */
public function isEmpty()
{
	return count($this->comments) === 0;
}

```

I went through to see if all ‘{}’ and ‘[]’ and ‘()’ are properly closed. Perhaps I’m missing one? This error seems to break both the Panel and the site itself.

[Next page](https://forum.getkirby.com/t/comments-plugin-for-kirby-v3/13299.md?page=2)
