When you enable social bookmarks, icons for sharing on Twitter, Facebook, and LinkedIn appear below your app’s content. Taglibs provide the markup you need to add this feature to your app.
Figure 1: These social bookmarks are in the inline display style.
Follow these steps to add social bookmarks to your app:
-
Make sure your entity is asset enabled.
-
In your project’s
build.gradle
file, add a dependency to the modulecom.liferay.social.bookmarks.taglib
:compileOnly group: "com.liferay", name: "com.liferay.social.bookmarks.taglib", version: "1.0.0"
-
Choose a view in which to show the social bookmarks. For example, you can display them in one of your app’s views. However, note that you don’t need to implement social bookmarks in your app’s asset renderers. The Asset Publisher displays social bookmarks in asset renderers by default.
-
In your view’s JSP, include the
liferay-social-bookmarks
taglib declaration:<%@ taglib uri="http://liferay.com/tld/social-bookmarks" prefix="liferay-social-bookmarks" %>
-
Get an instance of your entity. You can do this however you wish. This example uses
ParamUtil
to get the entity’s ID from the render request, then uses the entity’s-LocalServiceUtil
class to create an entity object:<% long entryId = ParamUtil.getLong(renderRequest, "entryId"); entry = EntryLocalServiceUtil.getEntry(entryId); %>
-
Use the
liferay-social-bookmarks:bookmarks
tag to add the social bookmarks component. See Social Bookmarks for information on this tag’s attributes. Here’s an example of using this tag to add social bookmarks for a blog entry in the Blogs app:<liferay-social-bookmarks:bookmarks className="<%= BlogsEntry.class.getName() %>" classPK="<%= entry.getEntryId() %>" displayStyle="inline" title="<%= entry.getTitle() %>" types="facebook,twitter" url="<%= PortalUtil.getCanonicalURL(bookmarkURL.toString(), themeDisplay, layout) %>" />