Thursday 13 March 2014

Custom Terms of condition page per site-Liferay

Hello,

Liferay very famous portal framework gives ability to add more then one sites in our portal instance.

It may happen that User want customized terms and condition page per site and we can easily achieve this goal through hook in Liferay and also manage it from user interface.

Lets go...Step by step,

1) Create "TERMS-OF-USE-PER-SITE" web content in particular site.Here please note that the name of the web content is important because hook fetch that content while showing terms and condition page to the user.
So in each and every site you have that above name page.
You can change the name of the page but for that you have to change your hook accordingly ;)

2)Create a hook in Liferay developer studio you can use eclipse with Liferay plugins as well.
Showing project structure as below.


3) Now add below content in terms_of_use.jsp




 <%@page import="com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil"%>  
 <%@page import="com.liferay.portlet.journal.model.JournalArticle"%>  
 <%@ include file="/html/portal/init.jsp" %>  
 <%  
 String currentURL = PortalUtil.getCurrentURL(request);  
 String termsofuse= "TERMS-OF-USE-PER-SITE";  
 String referer = ParamUtil.getString(request, WebKeys.REFERER, currentURL);  
 if (referer.equals(themeDisplay.getPathMain() + "/portal/update_terms_of_use")) {  
      referer = themeDisplay.getPathMain() + "?doAsUserId=" + themeDisplay.getDoAsUserId();  
 }  
 %>  
 <c:set var="articleCount" value="<%=JournalArticleLocalServiceUtil.getArticlesCount(themeDisplay.getScopeGroupId()) %>"/>  
 <aui:form action='<%= themeDisplay.getPathMain() + "/portal/update_terms_of_use" %>' name="fm">  
      <aui:input name="doAsUserId" type="hidden" value="<%= themeDisplay.getDoAsUserId() %>" />  
      <aui:input name="<%= WebKeys.REFERER %>" type="hidden" value="<%= referer %>" />  
      <c:choose>  
           <c:when test="<%=JournalArticleLocalServiceUtil.getArticlesCount(themeDisplay.getScopeGroupId()) > 0 %>">  
           <c:catch var ="catchException">  
                       <%String articleResourcePrimKey = JournalArticleLocalServiceUtil.getArticleByUrlTitle(themeDisplay.getScopeGroupId(), termsofuse).getArticleId();%>  
                     <liferay-ui:journal-article groupId="<%=themeDisplay.getScopeGroupId() %>" articleId="<%=articleResourcePrimKey %>" />  
           </c:catch>  
           </c:when>  
      </c:choose>  
                <c:if test = "${catchException != null || articleCount==0}" >  
                     <p>  your custom or default content
           </c:if>  
      <c:if test="<%= !user.isAgreedToTermsOfUse() %>">  
           <aui:button-row>  
                <aui:button type="submit" value="i-agree" />  
                <%  
                String taglibOnClick = "alert('" + UnicodeLanguageUtil.get(pageContext, "you-must-agree-with-the-terms-of-use-to-continue") + "');";  
                %>  
                <aui:button onClick="<%= taglibOnClick %>" type="cancel" value="i-disagree" />  
           </aui:button-row>  
      </c:if>  
 </aui:form>  


3) Add below content in liferay-hook.xml


 <?xml version="1.0"?>  
 <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">  
 <hook>  
      <language-properties>  
           content/Language_en.properties  
      </language-properties>  
      <custom-jsp-dir>/custom_jsps</custom-jsp-dir>  
 </hook>  

Anddd  you are done.....:D

Deploy the hook create web content with specific name as described in step 1.Which can be managed by User interface.

Thanks....GOOD DAY.

No comments:

Post a Comment