How to Create a Dynamic Page for Terms of Use
Introduction #
Liferay has a feature that allows forcing all users to accept a Terms of Use text before using the portal for the first time. A default text is included with the portal but in most installations using this feature this text will need to be customized. The simpler way to change that text is to modify the following JSP:
/html/portal/terms_of_use.jsp
That is probably all you need for simple sites, but for more complex ones it's useful to find a solution that allows changing the text of the Terms of Use dynamically. For example, by using a Web Content article (formerly Journal article). This solution is very useful when:
- The terms of use change frequently
- There is a need to have its text translated to several languages
- You want to use the established mechanics of Liferay to modify this text instead of having to get administrative access to change an already deployed jsp.
The following section explains how to achieve this.
Using a Web Content Article to manage the Terms of Use #
Using a Web Content Article to change the text of the Terms of Use varies depending on the version you use.
Liferay 5.2.x#
There are now properties you can use to specify an article to use and no code need by modified as the logic has been integrated into the portal. Use these values in your portal-ext.properties:
#
# Specify the articleId of a Journal Article to use for the terms of use.
#
terms.of.use.journal.article.id=
#
# Specify the groupId of the group to which the Journal Article specified by
# "terms.of.use.journal.article.id" belongs.
#
terms.of.use.journal.article.group.id=Note#
The groupId should be the identifier of the community where the article was created. Again, if you don't want to hardcode this id use the GroupService to obtain it dynamically from the community name. You can locate the GroupId for the Edit view on the Communities portlet, or from the Edit view of a particular Organization.
Prior to 5.2#
Note: This does not apply to all versions prior to 5.2 - see below if you are about to configure an older version - This article just mentioned "older" and "more recent" versions, I don't know when the changes occurred (somebody who knows should add this information)
You'll have to modify the following JSP:
/html/portal/terms_of_use.jsp
You can directly specify the articleId and groupId to the tag:
<liferay-ui:journal-article articleId="TERMS-OF-USE" groupId="<%= groupId %>" />
Older versions of Liferay#
You'll have to modify the following JSP:
/html/portal/terms_of_use.jsp
Remove all the text inside (but leave the form!) and copy it to a Journal Article of your choice. When creating the article give it an id that is easy to remember (if your portal is configured to allow for manual ids), such as TERMS-OF-USE.
Once the article is created you'll have to find it's resource primary key. As of now the UI doesn't show it, so you'll have to go to the database. If you gave the article an easy to remember id it'll be easier to find. Once you have the primary key add the following to the JSP above instead of the terms of text:
<liferay-ui:journal-article articleResourcePrimKey="<%= articleResourcePrimKey %>" />
If you don't want to hardcode the primary key of the article, you can obtain it using the Journal services from the groupId and the article id, for example:
<% JournalArticle article = JournalArticleLocalServiceUtil.getArticle(groupId, "TERMS-OF-USE"); long articleResourcePrimKey = article.getResourcePrimKey(); %> <liferay-ui:journal-article articleResourcePrimKey="<%= articleResourcePrimKey %>" />