我创建了一个基本上用于收集新闻文章信息的结构。其中一个字段是文章的日期。见图: structure for news
我从Asset Publisher中选择此结构,填写字段并保存。然后,我尝试查看资产发布者所在页面上的字段。我能够使用应用程序显示模板(ADT)访问和显示所有字段,但DATE除外!我已经在互联网上寻找答案,并转向社区寻求帮助。
这是我用来选择和格式化代码的应用程序显示模板的代码。
*免责声明:我不是java程序员,因此任何其他解释都会非常有用。
<div class="container news-listing">
<div class="row">
<div class="span9">
#if (!$entries.isEmpty())
#foreach ($entry in $entries)
#set($renderer = $entry.getAssetRenderer() )
#set($className = $renderer.getClassName() )
#if( $className == "com.liferay.portlet.journal.model.JournalArticle" )
#set( $journalArticle = $renderer.getArticle() )
#set( $document = $saxReaderUtil.read($journalArticle.getContent()) )
#set( $rootElement = $document.getRootElement() )
## FETCH Title
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='newstitle']") )
#set( $title = $xPathSelector.selectSingleNode($rootElement).getStringValue())
## FETCH image
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='featureimage']") )
#set( $img = $xPathSelector.selectSingleNode($rootElement).getStringValue())
## FETCH FullDescription
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='newsfulldescription']") )
#set( $fulldesc = $xPathSelector.selectSingleNode($rootElement).getStringValue() )
## FETCH ShortDescription
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='newsshortdescription']") )
#set( $shortdesc = $xPathSelector.selectSingleNode($rootElement).getStringValue() )
## FETCH date
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='articleDate']") )
#set( $datetest = $xPathSelector.selectSingleNode($rootElement).getStringValue() )
## FETCH Group
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='group']") )
#set( $Group = $xPathSelector.selectSingleNode($rootElement).getStringValue())
#set( $link = $assetPublisherHelper.getAssetViewURL($renderRequest, $renderResponse, $entry) )
#if ("$assetLinkBehavior" != "showFullContent")
#set( $link = $renderer.getURLViewInContext($renderRequest, $renderResponse, $link) )
#end
##$entry.getExpandoBridge().getAttributeNames()
$entry.date.getClass().getName()
<div class="listing">
<img src="$img" alt="$img" class="thumbnail">
<div class="news-info">
<div class="news-date">
<span>$datetest</span> <br/>
</div>
<p class="news-category">Announcement</p>
<h2>$title</h2>
<p>$shortdesc</br><a href="$link">Read More »</a></p>
</div>
</div>
#end
#end
#end
</div>
</div>
</div>
答案 0 :(得分:2)
模板编辑器(至少在Liferay 7中)允许您通过单击它们来添加字段。这是这个添加到模板的内容:
Freemarker的:
<#assign articleDate_Data = getterUtil.getString(articleDate.getData())>
<#if validator.isNotNull(articleDate_Data)>
<#assign articleDate_DateObj = dateUtil.parseDate("yyyy-MM-dd", articleDate_Data, locale)>
${dateUtil.getDate(articleDate_DateObj, "dd MMM yyyy - HH:mm:ss", locale)}
</#if>
或Velocity
#set ($articleDate_Data = $getterUtil.getString($articleDate.getData()))
#if ($validator.isNotNull($articleDate_Data))
#set ($articleDate_DateObj = $dateUtil.parseDate("yyyy-MM-dd",$articleDate_Data, $locale))
$dateUtil.getDate($articleDate_DateObj, "dd MMM yyyy - HH:mm:ss", $locale)
#end