Liferay + Journal Article Small Thumbnails

The following sample code show how to get the journal article small thumbnail display.


If you write the code like this, the liferay will not render the image for your.

  1.  
  2. <c:forEach items="${list}" var="journal">
  3.       ${journal.title}
  4.       < img src="${journal.smallImageURL}" />          
  5. </c:forEach>
  6.  

Solution :

Step 1) Remember import the require libraries

  1.  
  2. <%@ page import="java.util.*" %>
  3. <%@ page import="com.liferay.portlet.journal.model.JournalArticle" %>
  4. <%@ page import="com.liferay.portal.theme.ThemeDisplay" %>
  5. <%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
  6. <%@ page import="com.liferay.portal.kernel.servlet.ImageServletTokenUtil" %>
  7.  

Step 2)

  1.  
  2.  <%
  3.         List<JournalArticle> list = (List<JournalArticle>)request.getAttribute("list");
  4.         ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
  5.  
  6.         for (int i = 0; i < list.size(); i++)
  7.         {
  8.             JournalArticle journal = (JournalArticle)list.get(i);
  9. %>
  10.            
  11.            <%= journal.getTitle() %>
  12.            <img src="<%= themeDisplay.getPathImage()%>/image_gallery?img_id=<%= journal.getSmallImageId() %>&t=
  13.           <%= ImageServletTokenUtil.getToken(journal.getSmallImageId()) %>" width="100" height="100"/>        
  14. <%
  15.         }
  16. %>
  17.  

Done!

You can leave a response, or trackback from your own site.

Leave a Reply

Security Code: