Posted on Leave a comment

Determine Path to Portlet Assets in Liferay JSP Files

Liferay Logo

When developing the front end (i.e. templates and JSP files) for portlets you will definitely at some want to include/reference custom assets, such as images. Luckily, in Liferay in order to determine the path to your portlet’s assets you only need to follow two steps. In your view.jsp (or any custom JSP file for that matter):

  1. specify correct portlet taglib (Liferay 6+)
    <%@ taglib uri="" prefix="portlet"%>
  2. and to reference portlet assets use request.getContextPath(), e.g.
    <img src="<%=request.getContextPath()%>/img/filter.png" />
  3. That’s it. This works for all assets deployed inside your portlet.