Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
l ll
freemarker template
October 25, 2013 11:34 AM
Answer

l ll

Rank: Junior Member

Posts: 75

Join Date: December 12, 2011

Recent Posts

Lfr 6.2 rc2
How to get a variable "Title (Required)" from the freemarker template - Web Content Article?
If the custom field - then no problem

In velocity == $reserved-article-title.data avialable.
James Falkner
RE: freemarker template
October 3, 2013 6:32 AM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1362

Join Date: September 17, 2010

Recent Posts

d ll:
Lfr 6.2 rc2
How to get a variable "Title (Required)" from the freemarker template - Web Content Article?
If the custom field - then no problem



In velocity == $reserved-article-title.data avialable.


Well, that's quite annoying, isn't it! After some research, here's the solution: ${.vars['reserved-article-title'].data}

Read more....
l ll
RE: freemarker template
October 3, 2013 7:57 AM
Answer

l ll

Rank: Junior Member

Posts: 75

Join Date: December 12, 2011

Recent Posts

thank you
l ll
RE: freemarker template
October 23, 2013 9:32 AM
Answer

l ll

Rank: Junior Member

Posts: 75

Join Date: December 12, 2011

Recent Posts

Another question:
There is a field in the structure "documents_and_media1922".

I try to create a Display Template: Application Display Templates ==> Asset Publisher Template

 1
 2<#assign liferay_ui = taglibLiferayHash["/WEB-INF/tld/liferay-ui.tld"] />
 3<#list entries as entry>
 4 <#assign entry = entry />
 5 <#assign assetRenderer = entry.getAssetRenderer() />
 6         ${documents_and_media1922}<br>
 7         ${documents_and_media1922()}<br>
 8         ${entry.documents_and_media1922}<br>
 9         ${entry.documents_and_media1922.data}<br>
10         ${entry.documents_and_media1922()}<br>
11         ${assetRenderer.documents_and_media1922}<br>
12         ${assetRenderer.documents_and_media1922()}<br>
13         ${assetRenderer.documents_and_media1922.data}<br>
14</#list>


Any of these lines causes a fatal error

Expression entry.documents_and_media1922 is undefined on line 24, column 7 in 10157#10197#16440.
Ben Uphoff
RE: freemarker template
January 8, 2014 3:19 PM
Answer

Ben Uphoff

Rank: New Member

Posts: 9

Join Date: March 10, 2011

Recent Posts

How do I access custom variables in web content structures? For example, I have a structure called "standards", containing a text field called "standard". I'm using content from this structure in a "Related Asset Publisher" portlet, and it would seem I can access the standard metadata fields in the "entry" object, but how to I get at the custom fields? My goal is to create something like a dependent list, wherein selection of an asset from a browse/search return list in an asset publisher portlet causes various "related asset" portlets to refresh with, well, related assets! But, it's only useful if I can fully control the presentation of those related assets, including custom fields from their structures.

Thanks in-advance for any counsel! -Ben
James Falkner
RE: freemarker template
January 9, 2014 6:46 AM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1362

Join Date: September 17, 2010

Recent Posts

Ben Uphoff:
How do I access custom variables in web content structures? For example, I have a structure called "standards", containing a text field called "standard". I'm using content from this structure in a "Related Asset Publisher" portlet, and it would seem I can access the standard metadata fields in the "entry" object, but how to I get at the custom fields? My goal is to create something like a dependent list, wherein selection of an asset from a browse/search return list in an asset publisher portlet causes various "related asset" portlets to refresh with, well, related assets! But, it's only useful if I can fully control the presentation of those related assets, including custom fields from their structures.

Thanks in-advance for any counsel! -Ben


Custom fields that you create as part of a Web Content Structure are not made available in an Application Display Template in the same way they are when you are writing a Web Content Template. So you'll need to resort to parsing the article itself and either using looping structures or xpath expressions to get at the value. Here's an example of an Asset Publisher ADT that extracts and displays the value for a custom field I defined in a Web Content Structure called "Text1697", by using the built-in xml parser and an xpath expression:

1
2<#if entries?has_content>
3    <#list entries as entry>
4        <#assign docXml = saxReaderUtil.read(entry.getAssetRenderer().getArticle().getContent()) />
5        <#assign fieldVal = docXml.valueOf("//dynamic-element[@name='Text1697']/dynamic-content/text()") />
6        The value: ${fieldVal}
7    </#list>
8</#if>


You may also be interested in how and why that xpath expression works, I'd recommend reading Ray's excellent blog post (which is now a bit dated but the concepts remain the same).
Ben Uphoff
RE: freemarker template
January 9, 2014 12:17 PM
Answer

Ben Uphoff

Rank: New Member

Posts: 9

Join Date: March 10, 2011

Recent Posts

James - that worked perfectly - thanks! As a follow-up, do you know how I'd extract the data for the target URL so as to make the items in my new list "clickable"?

Ray's blog looks chock-full of info and good humor; I'll be poring over it to glean what I can.

Thanks again, Ben
James Falkner
RE: freemarker template
January 9, 2014 12:48 PM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1362

Join Date: September 17, 2010

Recent Posts

Ben Uphoff:
James - that worked perfectly - thanks! As a follow-up, do you know how I'd extract the data for the target URL so as to make the items in my new list "clickable"?

Ray's blog looks chock-full of info and good humor; I'll be poring over it to glean what I can.

Thanks again, Ben


Depending on the type of the field in the structure, the value returned from that xpath assign will be different. For "Documents and Media Gallery" fields, the returned value is the URL. So you can do something like

 1
 2<#if entries?has_content>
 3    <#list entries as entry>
 4        <#assign docXml = saxReaderUtil.read(entry.getAssetRenderer().getArticle().getContent()) />
 5        <#assign fieldVal = docXml.valueOf("//dynamic-element[@name='Text1697']/dynamic-content/text()") />
 6
 7        The value: ${fieldVal}
 8
 9        <#assign fieldVal2 = docXml.valueOf("//dynamic-element[@name='Documents_and_Media1730']/dynamic-content/text()") />
10
11        The DL value: <a href="${fieldVal2}">The Document</a>
12
13    </#list>
14</#if>
Ben Uphoff
RE: freemarker template
January 9, 2014 2:26 PM
Answer

Ben Uphoff

Rank: New Member

Posts: 9

Join Date: March 10, 2011

Recent Posts

Very helpful; I also found this article: https://www.liferay.com/community/wiki/-/wiki/Main/Rich+Summary+for+Asset+Publisher

Thanks again, James. -Ben
James Falkner
RE: freemarker template
January 10, 2014 7:27 AM
Answer

James Falkner

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1362

Join Date: September 17, 2010

Recent Posts

Ben Uphoff:
Very helpful; I also found this article: https://www.liferay.com/community/wiki/-/wiki/Main/Rich+Summary+for+Asset+Publisher

Thanks again, James. -Ben


Yeah, that is indeed very helpful for generating proper links to the individual Web Content articles themselves (which will properly send you to the correct page on which the article is displayed in its proper context).
Ben Uphoff
RE: freemarker template
May 16, 2014 9:15 AM
Answer

Ben Uphoff

Rank: New Member

Posts: 9

Join Date: March 10, 2011

Recent Posts

James,

We're now taking advantage of "Document Types", in that we added a metadata field to store some information about files we store in a Doc Library folder. And, we want to use a custom ADT to display this custom field along with the file. However, we're getting an error when trying to use the same approach as that for the journal articles and structures. Any hints on how to extract custom fields in an asset publisher when displaying assets of type "documents"?

Here's what we were using for the JAs:

<#assign docXml = saxReaderUtil.read(assetRenderer.getArticle().getContent()) />
<#assign fld_Publication_Date = docXml.valueOf("//dynamic-element[@name='Publication_Date']/dynamic-content/text()") />
${fld_Publication_Date}<br />

When we add metadata to a document type(under Site Admin --> Content -->Document and Media --> Manage --> Document Types), we are unable to print out the information in an ADT using the same technique above.

Thanks! -Ben
Ben Uphoff
RE: freemarker template
June 11, 2014 3:23 PM
Answer

Ben Uphoff

Rank: New Member

Posts: 9

Join Date: March 10, 2011

Recent Posts

Hoping James (or someone) might have an idea about how to pull these custom fields from a Document Type - anyone? Thanks. -Ben
Dave Weitzel
RE: freemarker template
October 15, 2014 5:52 AM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 194

Join Date: November 18, 2009

Recent Posts

Have you found out how to get to document type meta data yet?

My ADT I am using freemarker but I guess velocity would do if necessary.

I have failed to get to the StorageEngineUtil even using utilLocator.findUtil().

I have about 50 portlets that will relay on sorting b one of these document type fields (original publication date) so quite important.

I am willing to write a wiki article once some one delivers the magic code.

I am using the following sample snippets of code but all I get is a class name of com.sun.proxy
 1
 2<#if entries?has_content && serviceLocator?? >
 3    <#assign dlFileEntryService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService")>
 4    <#assign dlFileEntryTypeService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryTypeLocalService")>
 5    <#assign dlFileVersionService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileVersionLocalService")>
 6      <#assign dlFileEntryMetadataLocalService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryMetadataLocalService")>
 7    <#assign storageEngineUtil = utilLocator.findUtil("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil") >
 8
 9<#list entries as curEntry>
10    <#assign assetRenderer = curEntry.getAssetRenderer() />
11    <#assign entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale)) />
12    <#assign viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, curEntry) />
13     <#assign fileEntry = dlFileEntryService.getDLFileEntryByUuidAndCompanyId(curEntry.getClassUuid() , curEntry.getCompanyId() ) />
14       <#assign fileVersion= fileEntry.getFileVersion() />
15    <#assign fileEntryTypeId = fileEntry.getFileEntryTypeId() />
16   
17    <#if fileEntryTypeId gt 0 >
18            <#assign fileEntryType = dlFileEntryTypeService.getDLFileEntryType(fileEntryTypeId) />
19        <#assign dlFileVersion = dlFileVersionService.getLatestFileVersion(userId, fileEntry.getFileEntryId()) />
20        <#assign ddmStructures = fileEntryType.getDDMStructures()  />
21        <#list ddmStructures as curStructure>
22        <#assign fileEntryMetadata = dlFileEntryMetadataLocalService.getFileEntryMetadata(curStructure.getStructureId(), dlFileVersion.getFileVersionId()) />
23
24        DDMStorgageId = ${fileEntryMetadata.getDDMStorageId()}  <br />  PRINTS OK
25    ${storageEngineUtil.getClass().getClassName()}       PRINTS "com.sun.proxy.$Proxy554"
26   
27        <#assign fields = null >
28        <#assign fields = storageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId()) />  FAILS
29   
30        <#assign fieldNames = fields.getNames() />
31-   
32     </#list>
33    </#if>
34
35        <#if assetLinkBehavior != "showFullContent">
36            <#assign viewURL = assetRenderer.getURLViewInContext(renderRequest, renderResponse, viewURL) />
37        </#if>
38
39        <div class="asset-abstract container-fluid">
40            <div class="index span1" style="text-align:center">
41                <h1>${curEntry_index +1}<h1> ${curEntry.getClassPK()} | ${curEntry.getClassUuid()}
42            </div>
43
44            <div class="asset-content span7">
45                <h3 class="asset-title" style="margin:0 0 10px;line-height:25px;border:0"><a href="${viewURL}">${entryTitle}</a>
46                </h3>
47                ${fileEntry.getFolderId()} |    ${fileEntry.getFileEntryTypeId()} |
48               
49
50            </div>
51        </div>
52    </#list>
53</#if>
Ben Uphoff
RE: freemarker template
October 15, 2014 5:02 PM
Answer

Ben Uphoff

Rank: New Member

Posts: 9

Join Date: March 10, 2011

Recent Posts

Hi Dave,

Sorry - never did figure out how to access the document type meta data. What we ended up doing was using a normal Web Content Structure, along with an ADT to display it. And, I just added a "Document and Media" field to the Structure. Our ADT looks like this:

 1<#assign Publication_Date_DateObj = dateUtil.newDate(getterUtil.getLong(Publication_Date.getData()))>
 2<strong>${dateUtil.getDate(Publication_Date_DateObj, "MMMM d, yyyy", locale)}</strong><br />
 3
 4<#-- Title, if desired:
 5&mdash; ${.vars['reserved-article-title'].data}</strong><br />
 6-->
 7
 8${Abstract.getData()}<br />
 9<a href="${File.getData()}" class="learnmore">${languageUtil.format(locale, "download-x", "File")}</a><br />


Good luck. -Ben
Eduardo P. Garcia
RE: freemarker template
October 20, 2014 9:54 AM
Answer

Eduardo P. Garcia

LIFERAY STAFF

Rank: Junior Member

Posts: 37

Join Date: March 15, 2012

Recent Posts

Have a look to this thread.
Mohammad Hejazi
RE: freemarker template
November 10, 2014 7:03 AM
Answer

Mohammad Hejazi

Rank: New Member

Posts: 6

Join Date: November 9, 2014

Recent Posts

Thanks Very Good