留言板

Freemarker Display Date or Publish Date Variable?

thumbnail
Ken Driscoll,修改在10 年前。

Freemarker Display Date or Publish Date Variable?

Junior Member 帖子: 57 加入日期: 12-7-2 最近的帖子
Hi, I am creating a Freemarker Template in Liferay 6.2 for a web-content structure. I know in the past there were specific variables in Velocity for getting the display date ($reserved-article-display-date.data). Is there a similar variable in a Freemarker template for getting either the display date or the publish date?

Many thanks in advance!
thumbnail
James Falkner,修改在10 年前。

RE: Freemarker Display Date or Publish Date Variable? (答复)

Liferay Legend 帖子: 1399 加入日期: 10-9-17 最近的帖子
Ken Driscoll:
Hi, I am creating a Freemarker Template in Liferay 6.2 for a web-content structure. I know in the past there were specific variables in Velocity for getting the display date ($reserved-article-display-date.data). Is there a similar variable in a Freemarker template for getting either the display date or the publish date?

Many thanks in advance!


The same variables and their values are available in Freemarker too - but you have to use a slightly odd syntax due to the Freemarker syntax rules (where a dash means mathematical subtraction). So you can do
${.vars['reserved-article-display-date'].data}
thumbnail
Ken Driscoll,修改在10 年前。

RE: Freemarker Display Date or Publish Date Variable?

Junior Member 帖子: 57 加入日期: 12-7-2 最近的帖子
Thanks James!
thumbnail
Emil Öberg,修改在9 年前。

RE: Freemarker Display Date or Publish Date Variable?

New Member 帖子: 5 加入日期: 11-4-19 最近的帖子
For people like me Googling their way here:

When working with multilingual/non-English sites, date/time-stamp can be a bit of a headache as the date strings are strings with english words in them, such as Thu, 08 May 2014 11:48:00 +0000, rather than a unix timecode.

Here's an example of how to take a date/time-string (such as publish date), make it into a date/time-object and being able to print the date/time in the language/format you want. Just remove some excessive code if you're working with an English-only site.

https://gist.github.com/emiloberg/b4382b9a6946a183cddd
shima shima,修改在9 年前。

RE: Freemarker Display Date or Publish Date Variable?

Junior Member 帖子: 46 加入日期: 14-4-14 最近的帖子
it was very useful . would u plz explain more about reserved fields such as category, title, tages,.. . how can fetch them and show .
${ reserved -articlie- tilte.getData()} dose not workemoticon
thumbnail
Andew Jardine,修改在9 年前。

RE: Freemarker Display Date or Publish Date Variable?

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
I think you asked this one in another thread. don't wrap the variable name in curly braces {} ... velocity vars start with a $ and then go right into the name. So

${reserved-variable-name}.data

instead used --

$reserved-variable-name.data
shima shima,修改在9 年前。

RE: Freemarker Display Date or Publish Date Variable?

Junior Member 帖子: 46 加入日期: 14-4-14 最近的帖子
yes Andew I found my answer : ${.vars['reserved-article-title'].data}
this format works for all reserved value but what about tag and category"???emoticon
thumbnail
Andew Jardine,修改在9 年前。

RE: Freemarker Display Date or Publish Date Variable?

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
I don't think either of those (I know for sure that tags aren't) are part of the reserved list. You will need to load the service utils in the velocity template and then leverage the various api calls to get those details for the article.
shima shima,修改在9 年前。

RE: Freemarker Display Date or Publish Date Variable?

Junior Member 帖子: 46 加入日期: 14-4-14 最近的帖子
is there anybody could help more?
Mark M,修改在7 年前。

RE: Freemarker Display Date or Publish Date Variable?

New Member 发布: 1 加入日期: 17-1-6 最近的帖子
For Liferay 7.0 (using a Freemarker Template)

<!-- Load the List

<#assign records = ddlDisplayTemplateHelper.getRecords(reserved_record_set_id)>

<!-- Order the List

<#assign records = ddlDisplayTemplateHelper.getRecords(87355, -1, -1, -1, orderby)>

<!-- Replace 87355 with the 'Data Definition ID' of your list

<!-- render the records on the page

<#if records?has_content>
<#list records as cur_record>

<!-- all your styling and formatting here

</#list>
</#if>