Good morning everyone! I was wondering if it was easy to build a simple “Like”-feature with Kirby? Basically I have a blog and on the blogpost-page a user should be able to click a “Like”-button that increments a field in blogpost.txt by 1. I’m not worried about multiple clicks for now. I’ll take care of that later.
Is that possible? Any tips that point me in the right direction would be greatly appreciated!
Hey, thanks! I’ve already looked into that, but I wanted to check if there’s an easy way to get by without jQuery first If it turns out to be too much effort I’ll go for the plugin.
Ah, nice! Thanks for that. Didn’t know about the update()-method. I’ll just wrap it in a form and post via ajax then. Hope it’s really that easy, hehe.
Ah, true! Fixed the operator, still no luck with updating the likes count though. If I access http://localhost:3000/like:super-t in the browser it shows the homepage. I’ve set the blog-page to be the homepage and I’m omitting “blog” in the URLs of post-pages as explained here. Just in case that’s relevant.
Ah okay, I’ve changed that accordingly, but now when I open http://localhost:3000/like/super-t in the browser it redirects to the error page. I also get a 404 in the AJAX request.
Hmm, okay strange. I removed all other routes, but still no luck unfortunately. I still get the 404 when I access http://localhost:3000/blog/like/super-t and in the AJAX call. Here’s the current plugin file:
Nice, that was it! It works! Removed the method in the plugin and changed the AJAX call from POST to GET also. So it successfully updates the likes count if I pass a static value (e.g. 20) in the update function, but if I attempt to increment the count on each page reload, it doesn’t update at all. This is my current attempt:
We unfortunately can’t really help with line-by-line debugging. You need to test it yourself by adding dump statements here and there to check what the value is and where it gets wrong.