2014-02-25 113 views
0

我有一个基于结构和模板的Liferay WebContent。我想显示作者图片(来自Liferay UserProfile)作为模板的一部分。在WebContent上添加作者个人资料图片

有没有办法使用Velocity访问该信息?

我发现这个变量:

$reserved-article-author-id

然而,有一种简单的方法来获得使用的AuthorID的图片?

在个人资料页,照片显示是这样的:

的imgid是不一样的用户ID。有没有简单的方法从用户ID获取imgid?

Liferay Version是6.1。

回答

1

这应该在6.1工作:

#set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService")) 
#set ($user = $userLocalService.fetchUserById($getterUtil.getLong($reserved-article-author-id.data))) 
#set ($profilePicUrl = $request.theme-display.path-image + "/user_") 
#if ($user.isFemale()) 
    #set ($profilePicUrl = $profilePicUrl + "female") 
#else 
    #set ($profilePicUrl = $profilePicUrl + "male") 
#end 

#set ($profilePicUrl = $profilePicUrl + "_portrait?img_id=") 
#set ($profilePicUrl = $profilePicUrl + $user.getPortraitId()) 

<img src="$profilePicUrl" /> 

请注意,您必须journal.template.velocity.restricted.variables=portal-ext.properties文件,以允许访问$serviceLocator

+0

喜,我尝试过,但它不是工作国王......我在一个与结构相关的模板中使用了这个。即使将serviceLocator变量添加到portal-ext.properties(使用= serviceLocator)并确保加载正确的文件之后。如果我打印$ serviceLocator,$ serviceLocator是输出... – Martin

+0

没关系,你的确切版本是好的,但我发现一些文档试图用= serviceLocator的另一种方式发送给我...现在它应该工作.. – Martin

1

感谢您的回答,帮了我!在Liferay的6.2 GA2我

只是一件小事

#set ($profilePicUrl = $request.theme-display.path-image + "/user_") 

没有工作,似乎$ request.theme-display.path图像不工作在新版本中

但我解决这样的:

#set ($profilePicUrl = "$theme_display.getPathImage()" + "/user_") 

希望它可以帮助别人:)

+0

谢谢......最后,我还在实施中更改了一些细节以符合我的需求。 – Martin

0

在6.2这项工作:

试试这个:

#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService")) 
#set ($jaId = $getterUtil.getString($reserved-article-id.data)) 
#set ($ja = $journalArticleLocalService.getArticle($getterUtil.getLong($groupId),$jaId)) 

#set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService")) 
#set ($usuario = $userLocalService.getUserById($getterUtil.getLong($ja.getUserId()))) 
#set ($tD = $request.get("theme-display")) #set ($DigesterUtil = $portal.getClass().forName("com.liferay.portal.kernel.util.DigesterUtil")) 
#set ($DigesterUtil = $portal.getClass().forName("com.liferay.portal.kernel.util.DigesterUtil")) 


     #set ($profilePicUrl = $profilePicUrl + "_portrait?img_id=") 
     #set ($profilePicUrl = $profilePicUrl + $usuario.getPortraitId()) 


     #set ($profilePicUrl = $tD.get("path-image") + "/user_") 
     #if ($usuario.isFemale()) 
      #set ($profilePicUrl = $profilePicUrl + "female") 
     #else 
      #set ($profilePicUrl = $profilePicUrl + "male") 
     #end 

     #set ($profilePicUrl = $profilePicUrl + "_portrait?img_id=") 
     #set ($profilePicUrl = $profilePicUrl + $usuario.getPortraitId()) 

     #set ($profilePicUrl = $profilePicUrl + "&img_id_token=") 
     #set ($profilePicUrl = $profilePicUrl + $httpUtil.encodeURL($DigesterUtil.digest($usuario.getUuid()))) 

     <div class="img_user">   
      <img src="$profilePicUrl"/> 
     </div> 
0

下面是Liferay的6.2缩小版本:

#set($userConstants = $portal.getClass().forName("com.liferay.portal.model.UserConstants")) 
 

 
#set($portraitUrl = $userConstants.getPortraitURL($request.theme-display.path-image, $user.male, $user.portraitId, $user.userUuid))

问候, 马丁