掲示板

Getting ViewURL's from assetEntries in Journal Content Template

thumbnail
9年前 に Dave Weitzel によって更新されました。

Getting ViewURL's from assetEntries in Journal Content Template

Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
I have a journal content template that will allow users to select various categories and list the objects that exist in the system meeting them. (business need is archive by year)

I can retrieve the assets using AssetEntryQuery() but since I am in a CMS template I do not have access to portletResponse (nor technically portletRequest).

How do I get the viewURLs (or downloadURLs) for:

a) web content
b) documentFileEntries
c) calendar bookings

The AssetRenderer and AssetRendererHelper methods all require the portletResponse variable.

I guess I can look at the code that generated then for entering the AssetEntry system and clone that but hope there is a shorter way.

using 6.2 GA2 at the moment using Velocity for CMS templates had issues with Freemarker which I use for ADT templates
thumbnail
9年前 に Krzysztof Gołębiowski によって更新されました。

RE: Getting ViewURL's from assetEntries in Journal Content Template

Liferay Master 投稿: 549 参加年月日: 11/06/25 最新の投稿
Hello Dave,
Could you please paste the template here? I think I used the $request and $response objects in journal content templates without any problems. Unfortunately the only working example with assetRenderer I have is for ADT (build with Freemarker).

BTW, Why don't you want to use Category Navigation portlet together with Asset Publisher? It seems like a good case for this.

Regards,
KG
thumbnail
9年前 に Dave Weitzel によって更新されました。

RE: Getting ViewURL's from assetEntries in Journal Content Template

Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
Krzysztof Gołębiowski:
Hello Dave,
Could you please paste the template here? I think I used the $request and $response objects in journal content templates without any problems. Unfortunately the only working example with assetRenderer I have is for ADT (build with Freemarker).

BTW, Why don't you want to use Category Navigation portlet together with Asset Publisher? It seems like a good case for this.

Regards,
KG


I am copying some of the code from the template - there is much preamble from the user having option to select years and releases this code starts from having found the year and release categoryId's, but basically we have a set of assetEntry objects with no way in a web content template of accessing the assetRenderer.getURLxxxx methods as no response object is available You will see I actually use an UNDOCUMENTED method to get the article as otherwise that can be hard..

So work around for web content is to display in this template using request parameters (articleId) and for documents is to manually build the downloadURL



#set($url = $request.attributes.CURRENT_URL)
#set($url = $httpUtil.removeParameter($url, "articleId"))

## create assetEntry query based on category ID
## https://www.liferay.com/community/forums/-/message_boards/message/16795698

#set($definedCategoryIds = [])
#set($tempArr=[])
#set($void = $definedCategoryIds.add($getterUtil.getLong($yearCatId)))
#set($void = $definedCategoryIds.add($getterUtil.getLong($releaseCatId)))
#set($tempArr=$definedCategoryIds)
#set($arr=$tempArr.toArray($definedCategoryIds))
#set($longArray=$arrayUtil.toArray($arrayUtil.toLongArray($arr)))
#set($void=$assetEntryQuery.setAllCategoryIds($longArray))

## get web content entries

#set ($void =$assetEntryQuery.setClassName("com.liferay.portlet.journal.model.JournalArticle") ) 


#set ($entries = $assetEntryLocalService.getEntries($assetEntryQuery))

##number entries web content = $entries.size() <br>

<div class="container-fluid archives">

#if($myArticleId.length() &gt; 0 )
	#set ($article2 = $journalLocalService.getArticle($groupId, $myArticleId))
	$article2.getContentByLocale($locale.getLanguage() )
	<a href="$url"> &lt;&lt; Back  </a>
#else
<div class=""><h1>Web content</h1></div>

	#if($entries.size() &gt; 0 )
		#foreach ($curEntry in $entries)
		#set ($assetRenderer = $curEntry.getAssetRenderer() )
		#set ($article = $assetRenderer.getArticle() )
		#set ($articleId= $article.getArticleId() )
		#set ($viewURL = $url + "&amp;articleId=" + $articleId )

		<div class="results-row">
		<a href="$viewURL">$curEntry.getTitle($locale)</a>  $dateTool.format('EEE, MMM d, yyyy', $article.getDisplayDate()  )  
		</div>
		#end
	#else
	<div class="portlet-msg-info">No web content found</div>
	#end

#end


<hr>

## get document entries


#set ($VOID = $assetEntryQuery.setClassName("com.liferay.portlet.documentlibrary.model.DLFileEntry") ) 
#set ($docEntries = $assetEntryLocalService.getEntries($assetEntryQuery))

<div class=""><h1>Documents / Attachments</h1></div>

#if($docEntries.size() &gt; 0 )
	#foreach ($curEntry in $docEntries)
	#set ($assetRenderer = $curEntry.getAssetRenderer() )
	#set ($classPK =$curEntry.getClassPK() )
	#set ($fileEntry = $dlAppLocalService.getFileEntry( $classPK ) )
	#set ($fileVersion = $fileEntry.getFileVersion() )
	#set ($title= $httpUtil.encodeURL($htmlUtil.unescape($fileEntry.getTitle() ) ) )
	#set ($sb = "/documents/" + $fileEntry.getRepositoryId() + "/" + $fileEntry.getFolderId() + "/" + $title + "/" + $fileEntry.getUuid() )

	<div class="row-fluid results-row">
	<a href="$sb"><img src="${request.theme-display.path-theme-images}/common/download.png">
	$curEntry.getTitle($locale)</a> $dateTool.format('EEE, MMM d, yyyy', $curEntry.getModifiedDate() )  
	</div>
	#end
#else
	<div class="portlet-msg-info">No documents found</div>
#end

## get calendar entries



</div>


The category navigation portlet only allows you to use one category AFAIK, I need to have minimum of two and may be four categories for each section of the user interface (above only covers general web content and documents).

I am also trying to recall why I couldn't use freemarker, I think because the liferayTaglibHash object isn't available in journal content templates which given access to taglibs is the top reason for using in AssetDisplayTemplates seems odd. May revisit on next WCM template