Foros de discusión

Conversion to velocity from freemarker.

thumbnail
Praful Shukla, modificado hace 8 años.

Conversion to velocity from freemarker.

Junior Member Mensajes: 46 Fecha de incorporación: 29/09/15 Mensajes recientes
I want to convert the following code into velocity:
<#function getDLFileEntryFieldsMap dlFileEntry>
<#assign fileVersionId = dlFileEntry.getLatestFileVersion(true).getFileVersionId() />
<#return dlFileEntry.getFieldsMap(fileVersionId) />
</#function>
<#function getDLFileEntryFieldValue fieldsMap fieldName>
<#list fieldsMap?keys as structureKey>
<#list fieldsMap[structureKey].iterator() as field>
<#if field.getName() = fieldName>
<#return field.getValue()>
</#if>
</#list>
</#list>
<#return "">
</#function>

Can anyone help me to sort this out..??
thumbnail
James Falkner, modificado hace 8 años.

RE: Conversion to velocity from freemarker.

Liferay Legend Mensajes: 1399 Fecha de incorporación: 17/09/10 Mensajes recientes
I recommend reading up on Velocity and trying to convert this to a macro. It seems not too complex...

Also I personally think FreeMarker is superior and has lots of features that Velocity doesn't have, so why do you want to convert?
thumbnail
Praful Shukla, modificado hace 8 años.

RE: Conversion to velocity from freemarker.

Junior Member Mensajes: 46 Fecha de incorporación: 29/09/15 Mensajes recientes
Actually I've created the following Velocity Template to get Images in the Media Gallery along with information related to a particular Image such as its Titlt,Description,ImageType,etc...


<style>
#images{
display:inline-block;
}
</style>
 
#if (!$entries.isEmpty())
	#foreach ($curFileEntry in $entries)
	<div id="images">
	<img src="$dlUtil.getPreviewURL($curFileEntry, $curFileEntry.FileVersion,themeDispay, " ") height="320" width="372" "><br>
	Title:$curFileEntry.title<br>
    Date:$curFileEntry.getCreateDate()<br>
    Description:$curFileEntry.getDescription()<br>
    Image Type:$curFileEntry.getMimeType()<br> 
    <hr>
	</div>
	#end
    #end


Now I want to show values associated with Document Type for each image....
And not able to get any code in Velocity Template
Can you help me over this...??
thumbnail
Andrew Jardine, modificado hace 8 años.

RE: Conversion to velocity from freemarker.

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Can you elaborate on this?

Now I want to show values associated with Document Type for each image....


.. when you say type, I am guessing you are not referring to the mime type as the code you provided seems to show that you are already pulling it. What other information, specifically, are you looking for?
thumbnail
Praful Shukla, modificado hace 8 años.

RE: Conversion to velocity from freemarker.

Junior Member Mensajes: 46 Fecha de incorporación: 29/09/15 Mensajes recientes
Following is the procedure to create document type:
1)Admin ->Content
2)Documents and Media
3)Manage-> Document Type
4)Create a new document type with fields
Let us say that i've created two fields i.e. Name & Adderess associated with each image.
Now I want to show the values of these two fields along with images in the media gallery.
Can you sort this out..??
thumbnail
Andrew Jardine, modificado hace 8 años.

RE: Conversion to velocity from freemarker.

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Praful,

I see. Ok -- well, the DocumentType objects are stored in the DDMStructure table, just like web content structures. There is a relationship table between the DLFileEntryType and the DDMStructure. You should be able to use the fileEntryTypeId attribute from the DLFileEntry object in conjunction with the DLFileEntryTypeLocalServiceUtil.getDLFileEntryType(long) method to get the object (all using the service locator of course).

Let me know if that solves your problem.
thumbnail
Praful Shukla, modificado hace 8 años.

RE: Conversion to velocity from freemarker.

Junior Member Mensajes: 46 Fecha de incorporación: 29/09/15 Mensajes recientes
I am not able to solve this..
Will you please explain it more..??
thumbnail
Andrew Jardine, modificado hace 8 años.

RE: Conversion to velocity from freemarker.

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Praful,

I did some digging but ran into the same rats nest you have I suspect. When this happens to me I try to find an example in the portal itself where I can stufdy the code to better understand how it works. Here is what I did.

1. I create a custom document structure with two fields - a boolean and a text field.
2. I created a new document with this custom structure and populated my custom structure fields with values.
3. I then edited the file entry I created and noticed on the right side a panel with my custom structure fields and values.

I went looking for this JSP and found it in /html/portlet/document_library/view_file_entry.jsp. Studyign this file I found the section that appears to render this content


				
<liferay-ui:panel-container extended="<%= false %>" id="documentLibraryAssetPanelContainer" persiststate="<%= true %>"> &lt;% if (fileEntryTypeId &gt; 0) { try { DLFileEntryType fileEntryType = DLFileEntryTypeServiceUtil.getFileEntryType(fileEntryTypeId); List<ddmstructure> ddmStructures = fileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { Fields fields = null; try { DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), fileVersionId); fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId()); } catch (Exception e) { } %&gt; <liferay-ui:panel collapsible="<%= true %>" cssclass="metadata" extended="<%= true %>" id="documentLibraryMetadataPanel" persiststate="<%= true %>" title="<%= HtmlUtil.escape(ddmStructure.getName(locale)) %>"> <liferay-ddm:html classNameId="<%= PortalUtil.getClassNameId(DDMStructure.class) %>" classPK="<%= ddmStructure.getPrimaryKey() %>" fields="<%= fields %>" fieldsNamespace="<%= String.valueOf(ddmStructure.getPrimaryKey()) %>" readOnly="<%= true %>" requestedLocale="<%= locale %>" /> </liferay-ui:panel> &lt;% } } catch (Exception e) { } } %&gt; </ddmstructure></liferay-ui:panel-container>


It looks like they use a tag to render the fields (/html/taglib/ddm). I haven't studied the start.jsp files in there but there may be more useful details for you there.

This might not be the exact answer you are looking for but the code might help you understand how you can retrieve the fields for your document structure.