This guide explains how you can add a 'like' button to pages, comments and attachments in Scroll Viewport.
Please note that only logged-in users can like content using this button.
Implement a like button
Firstly, add this code to your <head> element:
Then, place this code next to the content that you want to add a like button to:
In this example, the
$page.id', meaning that this code will add a like button to the page itself.
However, you can also change the
data-content-idvalue to the element id of comments and attachments to give them a like button.
- Now, embed this script in the page:
Of course, this code is just an example. For instance, you could delete the text in line 41 if you don't want to display the number of likes.
Modifying the code
After the buttons are initialized, inspecting their REST API HTTP call will return data that developers can use to expand the code in various ways:
The information reported here includes the following data:
|content_id||the content's unique identifier|
|content_type||the type of content (page, comment or attachment)|
expanding this displays a list of all users who have liked this element. The following information fields are displayed:
|summary||the text that appears after the user clicks the like button|
This is what the button (made with unedited code from above, and unstyled) looks when implemented for page comments: