Sisältöjulkaisija

Takaisin

IoT - yhdeksänkymmentä vuotta vanhaa hypeä vai uuden digitalouden polttoainetta?

Virhe tapahtui prosessoidessa esitysmallia.
Can't parse template-datetime-format to a date format.
1<#-- display-name: Blog --> 
2<#-- source-path: blog.ftl --> 
3<#assign title = .vars['reserved-article-title'].data> 
4<#assign lead = lead.getData()> 
5<#assign body = body.getData()> 
6 
7<#-- ----------------------------------------------------------------- ->  
8
9 - GETTING REAL TIME/DATE-STAMP  
10
11 - When we ask Liferay for the create date of an article (or really we 
12 - ask Liferay for the 'display-date' which is settable by the user) we get 
13 - a string looking like this: 'Thu, 08 May 2014 11:48:00 +0000'. This 
14 - string will always be in english and when we want to create a datetime 
15 - object from it, we need to parse it with english locale. 
16
17 - Therefor, when working with a non-english site we need to: 
18 -   1) Save the original locale (e.g. 'sv_SE') to a variable 
19 -   2) Set locale to 'en_US' 
20 -   3) Parse the date string and create a date object from it 
21 -   4) Set locale back to original locale, from variable. 
22 -   5) Create a date string from the date object. 
23
24 - Common pitfall: 
25 - Swedish example: Most dates have similar names in Swedish and English. 
26 - e.g.: the English dates '08 Jan 2014', '08 Feb 2014', '08 Mar 2014', 
27 -       '08 Apr 2014' are all the same as their Swedish counterpart, 
28 -       and are therefor parseable without doing any magic. 
29
30 -       However '08 May 2014' is not the same in Swedish ('08 maj 2014'), 
31 -       neither is 'oct'/'okt'. 
32
33 -       When developing, make sure you're working with content with 
34 -       display-date may or october. 
35
36<- ------------------------------------------------------------------ --> 
37 
38 
39<#-- Get Display Date (not created-date which is equal to when a user last 
40     modified the content)  
41--> 
42<#assign date = .vars['reserved-article-display-date'].data> 
43 
44<#-- Load timezone from language files, as we have multiple timezones. 
45     If we just had one timezone, set it like: 
46     <#setting time_zone = "Europe/Stockholm"> 
47--> 
48<#setting time_zone = languageUtil.get(locale, "template-timezone")> 
49 
50<#-- Saving original locale to be able to reset it to that later --> 
51<#assign originalLocale = locale> 
52 
53<#-- Set locale to en_US to be able to parse the date string and make it a date object --> 
54<#setting locale = 'en_US'> 
55<#assign date = date?datetime("EEE, d MMM yyyy HH:mm:ss Z")> 
56 
57<#-- Set locale to the real (original) locale  --> 
58<#setting locale = originalLocale> 
59 
60<#-- As we want to display the date in different formats depending on the  
61     language we get the date/time-format from the language files. Else 
62     we could set it like this: 
63     <#assign dateTimeFormat = "d MMMM yyyy"> 
64--> 
65<#assign dateTimeFormat = languageUtil.get(locale, "template-datetime-format")> 
66 
67<#-- Create a date string from the date object --> 
68<#assign date = date?string(dateTimeFormat)> 
69 
70<#-- END GETTING REAL TIME/DATE-STAMP --> 
71<#-- ----------------------------------------------------------------- -->  
72 
73 
74 
75 
76<#if title?has_content> 
77	<h1>${title}</h1> 
78</#if> 
79 
80<#if date?has_content> 
81	<p class="inline-date-tag">${languageUtil.get(locale, "template-published")} ${date}</p> 
82</#if> 
83 
84<#if lead?has_content> 
85	<p class="leader"> 
86		${lead} 
87	</p> 
88</#if> 
89 
90<#if body?has_content> 
91	${body} 
92</#if>