2

I'm using Liferay 7 and by looking at the default adts for asset publisher I see, in the "Rich Summary" adt, the following portion of code

<#list entries as entry>
  <#assign
    entry = entry
    assetRenderer = entry.getAssetRenderer()
    entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale))
    viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, entry)
  />
  ...

(see it on GitHub https://github.com/liferay/liferay-portal/blob/master/portal-web/test/functional/com/liferay/portalweb/dependencies/adt_asset_publisher_rich_summary.ftl)

Is there any reason for doing the entry = entry assignment?

It seems to me like that shouldn't be necessary, am I maybe missing some reason why it might be necessary in freemarker such an assignment?

[edit]

Considering that this way entry will be defined even outside the list loop, why was this done? Is it necessary?

In this template there are actually no more references to this variable. So is this assignement needed while creating a new custom adt?

Carlo
  • 642
  • 1
  • 5
  • 16

2 Answers2

3

As #assign creates/writes a variable in the namespace of the current template, while #list creates a variable in the scope of the loop (a more specific, narrower scope), that statement copies entity from the loop scope to the wider template namespace scope. If it's really needed in that template, I don't know; look for references to entry in that (or an #include/#imported-d) template that is outside the #list. It's not needed in the part quoted.

ddekany
  • 29,656
  • 4
  • 57
  • 64
1

This is due to the use of macros, outside the loop at the bottom of this file.

Victor
  • 3,520
  • 3
  • 38
  • 58