Fórum

freemarker template

d ll, modificado 10 Anos atrás.

freemarker template

Regular Member Postagens: 158 Data de Entrada: 12/12/11 Postagens Recentes
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.
thumbnail
James Falkner, modificado 10 Anos atrás.

RE: freemarker template

Liferay Legend Postagens: 1399 Data de Entrada: 17/09/10 Postagens Recentes
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....
d ll, modificado 10 Anos atrás.

RE: freemarker template

Regular Member Postagens: 158 Data de Entrada: 12/12/11 Postagens Recentes
thank you
d ll, modificado 10 Anos atrás.

RE: freemarker template

Regular Member Postagens: 158 Data de Entrada: 12/12/11 Postagens Recentes
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


<#assign liferay_ui = taglibLiferayHash["/WEB-INF/tld/liferay-ui.tld"] />
<#list entries as entry>
 <#assign entry = entry />
 <#assign assetRenderer = entry.getAssetRenderer() />
         ${documents_and_media1922}<br>
		 ${documents_and_media1922()}<br>
		 ${entry.documents_and_media1922}<br>
		 ${entry.documents_and_media1922.data}<br>
		 ${entry.documents_and_media1922()}<br>
		 ${assetRenderer.documents_and_media1922}<br>
		 ${assetRenderer.documents_and_media1922()}<br>
		 ${assetRenderer.documents_and_media1922.data}<br>
<!--#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, modificado 10 Anos atrás.

RE: freemarker template

New Member Postagens: 9 Data de Entrada: 10/03/11 Postagens Recentes
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
thumbnail
James Falkner, modificado 10 Anos atrás.

RE: freemarker template

Liferay Legend Postagens: 1399 Data de Entrada: 17/09/10 Postagens Recentes
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:


&lt;#if entries?has_content&gt;
	&lt;#list entries as entry&gt;
        &lt;#assign docXml = saxReaderUtil.read(entry.getAssetRenderer().getArticle().getContent()) /&gt;
        &lt;#assign fieldVal = docXml.valueOf("//dynamic-element[@name='Text1697']/dynamic-content/text()") /&gt;
        The value: ${fieldVal}
	<!--#list-->
<!--#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, modificado 10 Anos atrás.

RE: freemarker template

New Member Postagens: 9 Data de Entrada: 10/03/11 Postagens Recentes
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
thumbnail
James Falkner, modificado 10 Anos atrás.

RE: freemarker template

Liferay Legend Postagens: 1399 Data de Entrada: 17/09/10 Postagens Recentes
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


&lt;#if entries?has_content&gt;
	&lt;#list entries as entry&gt;
        &lt;#assign docXml = saxReaderUtil.read(entry.getAssetRenderer().getArticle().getContent()) /&gt;
        &lt;#assign fieldVal = docXml.valueOf("//dynamic-element[@name='Text1697']/dynamic-content/text()") /&gt;

        The value: ${fieldVal}

        &lt;#assign fieldVal2 = docXml.valueOf("//dynamic-element[@name='Documents_and_Media1730']/dynamic-content/text()") /&gt;

        The DL value: <a href="${fieldVal2}">The Document</a>

	<!--#list-->
<!--#if-->
Ben Uphoff, modificado 10 Anos atrás.

RE: freemarker template

New Member Postagens: 9 Data de Entrada: 10/03/11 Postagens Recentes
Very helpful; I also found this article: https://www.liferay.com/community/wiki/-/wiki/Main/Rich+Summary+for+Asset+Publisher

Thanks again, James. -Ben
thumbnail
James Falkner, modificado 10 Anos atrás.

RE: freemarker template

Liferay Legend Postagens: 1399 Data de Entrada: 17/09/10 Postagens Recentes
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, modificado 9 Anos atrás.

RE: freemarker template

New Member Postagens: 9 Data de Entrada: 10/03/11 Postagens Recentes
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, modificado 9 Anos atrás.

RE: freemarker template

New Member Postagens: 9 Data de Entrada: 10/03/11 Postagens Recentes
Hoping James (or someone) might have an idea about how to pull these custom fields from a Document Type - anyone? Thanks. -Ben
thumbnail
Dave Weitzel, modificado 9 Anos atrás.

RE: freemarker template

Regular Member Postagens: 208 Data de Entrada: 18/11/09 Postagens Recentes
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

&lt;#if entries?has_content &amp;&amp; serviceLocator?? &gt;
	&lt;#assign dlFileEntryService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService")&gt;
	&lt;#assign dlFileEntryTypeService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryTypeLocalService")&gt;
	&lt;#assign dlFileVersionService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileVersionLocalService")&gt;
      &lt;#assign dlFileEntryMetadataLocalService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryMetadataLocalService")&gt;
	&lt;#assign storageEngineUtil = utilLocator.findUtil("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil") &gt; 

&lt;#list entries as curEntry&gt;
	&lt;#assign assetRenderer = curEntry.getAssetRenderer() /&gt;
	&lt;#assign entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale)) /&gt;
	&lt;#assign viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, curEntry) /&gt;
     &lt;#assign fileEntry = dlFileEntryService.getDLFileEntryByUuidAndCompanyId(curEntry.getClassUuid() , curEntry.getCompanyId() ) /&gt;
   	&lt;#assign fileVersion= fileEntry.getFileVersion() /&gt;
    &lt;#assign fileEntryTypeId = fileEntry.getFileEntryTypeId() /&gt;
	
    &lt;#if fileEntryTypeId gt 0 &gt;
    		&lt;#assign fileEntryType = dlFileEntryTypeService.getDLFileEntryType(fileEntryTypeId) /&gt;
		&lt;#assign dlFileVersion = dlFileVersionService.getLatestFileVersion(userId, fileEntry.getFileEntryId()) /&gt;
		&lt;#assign ddmStructures = fileEntryType.getDDMStructures()  /&gt;
		&lt;#list ddmStructures as curStructure&gt;
		&lt;#assign fileEntryMetadata = dlFileEntryMetadataLocalService.getFileEntryMetadata(curStructure.getStructureId(), dlFileVersion.getFileVersionId()) /&gt;

		DDMStorgageId = ${fileEntryMetadata.getDDMStorageId()}  <br>  PRINTS OK
	${storageEngineUtil.getClass().getClassName()}       PRINTS "com.sun.proxy.$Proxy554"
	
		&lt;#assign fields = null &gt;
		&lt;#assign fields = storageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId()) /&gt;  FAILS
	
		&lt;#assign fieldNames = fields.getNames() /&gt;
-	
     <!--#list-->
	<!--#if-->

		&lt;#if assetLinkBehavior != "showFullContent"&gt;
			&lt;#assign viewURL = assetRenderer.getURLViewInContext(renderRequest, renderResponse, viewURL) /&gt;
		<!--#if-->

		<div class="asset-abstract container-fluid">
			<div class="index span1" style="text-align:center">
				<h1>${curEntry_index +1}</h1><h1> ${curEntry.getClassPK()} | ${curEntry.getClassUuid()}
			</h1></div>

			<div class="asset-content span7">
				<h3 class="asset-title" style="margin:0 0 10px;line-height:25px;border:0"><a href="${viewURL}">${entryTitle}</a> 
				</h3> 
				${fileEntry.getFolderId()} |	${fileEntry.getFileEntryTypeId()} |
				

			</div>
		</div>
	<!--#list-->
<!--#if-->

Ben Uphoff, modificado 9 Anos atrás.

RE: freemarker template

New Member Postagens: 9 Data de Entrada: 10/03/11 Postagens Recentes
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:

&lt;#assign Publication_Date_DateObj = dateUtil.newDate(getterUtil.getLong(Publication_Date.getData()))&gt;
<strong>${dateUtil.getDate(Publication_Date_DateObj, "MMMM d, yyyy", locale)}</strong><br>

&lt;#-- Title, if desired:
— ${.vars['reserved-article-title'].data}<br>
--&gt;

${Abstract.getData()}<br>
<a href="${File.getData()}" class="learnmore">${languageUtil.format(locale, "download-x", "File")}</a><br>


Good luck. -Ben
thumbnail
Eduardo P. García, modificado 3 Anos atrás.

RE: freemarker template

Regular Member Postagens: 157 Data de Entrada: 16/03/12 Postagens Recentes
Have a look to this thread.
thumbnail
selam Aweke selam, modificado 7 Anos atrás.

RE: freemarker template

Junior Member Postagens: 60 Data de Entrada: 14/11/12 Postagens Recentes
how can we access the URL of document media ?
thumbnail
Mohammad Hejazi, modificado 9 Anos atrás.

RE: freemarker template

New Member Postagens: 6 Data de Entrada: 09/11/14 Postagens Recentes
Thanks Very Good
Jeffery Nguyen, modificado 7 Anos atrás.

RE: freemarker template

New Member Mensagem: 1 Data de Entrada: 13/01/16 Postagens Recentes
James Falkner:
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


&lt;#if entries?has_content&gt;
	&lt;#list entries as entry&gt;
        &lt;#assign docXml = saxReaderUtil.read(entry.getAssetRenderer().getArticle().getContent()) /&gt;
        &lt;#assign fieldVal = docXml.valueOf("//dynamic-element[@name='Text1697']/dynamic-content/text()") /&gt;

        The value: ${fieldVal}

        &lt;#assign fieldVal2 = docXml.valueOf("//dynamic-element[@name='Documents_and_Media1730']/dynamic-content/text()") /&gt;

        The DL value: <a href="${fieldVal2}">The Document</a>

	<!--#list-->
<!--#if-->



Hi, looking for something along the lines of this but I am working with Documents and Media. When I obtain the AssetRenderer I get the DLFileEntryAssetRenderer which doesn't have getArticle.

How do I go about this issue? Any idea?