How to open URL in maximized mode in Application Display Template? - liferay

I have created and ADT (Application Display Template) for Asset Publisher which displays web-contents. If a link is clicked the web-content should open in maximized mode.
<#if entries?has_content>
<#list entries as entry>
<#assign renderer = entry.getAssetRenderer() />
<#assign className = renderer.getClassName() />
<#if className == "com.liferay.portlet.journal.model.JournalArticle">
<#assign journalArticle = renderer.getArticle() />
<#assign document = saxReaderUtil.read(journalArticle.getContentByLocale(locale.toString())) />
<#assign assetURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse,entry) />
<div class="molisana-product">
<a href="${assetURL}">
<h3 class="product-title">
${entry.getTitle(locale)}
</h3>
</a>
</div>
</#if>
</#list>
</#if>
The important bit is :
<#assign assetURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse,entry) />
I tried with setWindowState <a href="${assetURL.setWindowState(WindowState.MAXIMIZED)}"> but doesn't work.

Related

How to embed a portlet in Asset Publisher?

I want to embed a portlet in an Asset Publisher in Liferay 6.2.
I did this:
<#assign siteMapPortletId = "85" />
<#assign PortletPreferencesFactoryUtil = staticUtil["com.liferay.portlet.PortletPreferencesFactoryUtil"] />
<#assign portletSetupFooter = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, siteMapPortletId) />
<#if portletSetupFooter.getValue("portletSetupShowBorders", "") != "false">
<#assign myPreferences = portletSetupFooter.setValue("portletSetupShowBorders", "false") />
</#if>
<#assign myPreferences = portletSetupFooter.setValue("rootLayoutUuid", getPageID("Pages")) />
<#assign myPreferences = portletSetupFooter.setValue("displayStyle", getTemplateID("Sitemap")) />
<#assign myPreferences = portletSetupFooter.store() />
<#assign liferay_portlet = taglibLiferayHash["/WEB-INF/tld/liferay-portlet.tld"] />
<#liferay_portlet["runtime"]
defaultPreferences=myPreferences
portletName=siteMapPortletId
/>
but I get this error:
liferay_portlet["runtime"] not found.

set web content default preferences of portlet freemarker and liferay 7

I read that I can set a default content to display in a portlet into the theme layout, with this code:
<#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone") />
<#assign VOID = freeMarkerPortletPreferences.setValue("groupId", "37295") />
<#assign VOID = freeMarkerPortletPreferences.setValue("articleId", "46616") />
<#liferay_portlet["runtime"]
defaultPreferences="${freeMarkerPortletPreferences}"
instanceId="quick_links"
portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet"/>
but when I did this, the portlet display that I need set a web content to display:
I have hardcode the groupId because the web content that I want display was created on another site.
I think you have a typo... check this example (https://dev.liferay.com/pt/develop/tutorials/-/knowledge_base/7-0/applying-portlet-decorators-to-embedded-portlets)
<#assign VOID =
freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId",
"barebone")>
<div aria-expanded="false" class="collapse navbar-collapse"
id="navigationCollapse">
<#if has_navigation && is_setup_complete>
<nav class="${nav_css_class} site-navigation"
id="navigation" role="navigation">
<div class="navbar-form navbar-right" role="search">
<#liferay.search default_preferences=
"${freeMarkerPortletPreferences}" />
</div>
<div class="navbar-right">
<#liferay.navigation_menu default_preferences=
"${freeMarkerPortletPreferences}" />
</div>
</nav>
</#if>
</div>
<#assign VOID = freeMarkerPortletPreferences.reset()>

How can I get repeatable field values of a Document Type (WCM) via Application Display Template (ADT)?

I have this Document Type Structure:
I can get the value of the fields that do not have a children (in this example the field with the name Field):
<#if imageMimeTypes?seq_contains(entry.getMimeType()) >
<#assign fileEntryType = DLFileEntryTypeService.getFileEntryType(fileEntryTypeId) />
<#assign dlFileVersion = DLFileVersionService.getLatestFileVersion(fileEntry.getUserId(), fileEntry.getFileEntryId()) />
<#assign fieldsMap = fileEntry.getFieldsMap(dlFileVersion.getFileVersionId()) />
<#list fieldsMap?keys as structureKey>
<#list fieldsMap[structureKey].iterator() as field>
<#if field.getName() == 'Field'>
<#assign Field = field.getValue() />
</#if>
</#list>
</#list>
Value: ${Field}
</#if>
But when I have a repeatable field with children fields I can't get neither the value of the repeatable field nor the value of its children.
<#list fieldsMap?keys as structureKey>
<#list fieldsMap[structureKey].iterator() as field>
<#if field.getName() == 'Repeatable_field'>
<#assign RepeatableField = field.getName() />
</#if>
</#list>
</#list>
Value: ${RepeatableField}
I get this error:
Expecting a string, date or number here, Expression RepeatableField
is instead a freemarker.template.SimpleSequence
UPDATE:
I managed to get the value of Repeatable_field using field.getValues(locale) method.
But I still can't get the value of its children:
<#list fieldsMap?keys as structureKey>
<#list fieldsMap[structureKey].iterator() as field>
<#if field.getName() == 'Repeatable_field'>
<#assign repeatableFieldValues = field.getValues(locale) />
<#list repeatableFieldValues as val>
<#assign Field = val /><#-- parent Value -->
<#-- assign childrenField = val.Children_field.getValue() --><#-- children Value -->
</#list>
</#if>
</#list>
</#list>
In Liferay 7.3, I get the repeatable field values within the ADT in this way:
<#if entries?has_content>
<#list entries as entry>
<#if entry.getClassName() == "com.liferay.journal.model.JournalArticle" >
<#assign assetRenderer = entry.getAssetRenderer() />
<#assign article = assetRenderer.getArticle() />
<#assign articleStructure = article.getDDMStructure() />
<#assign articleStructureFields = articleStructure.getRootFieldNames() />
<#assign document = saxReaderUtil.read(article.getContent()) />
<#assign rootElement = document.getRootElement() />
<#list articleStructureFields as field>
<#attempt>
<#assign xPathSelectorDocument = saxReaderUtil.createXPath("dynamic-element[#name='${field}']") />
<#assign fieldContent = xPathSelectorDocument.selectSingleNode(rootElement).getStringValue() />
<#assign fieldNodes = xPathSelectorDocument.selectNodes(rootElement) />
<#if field == 'User'> <#-- Field - Simple -->
<#assign user = fieldContent />
<#elseif field == 'Actions'> <#-- Field - Repeatable -->
<#assign listActions = [] />
<#list fieldNodes as node>
<#assign listActions = listActions + [node.getStringValue()] />
</#list>
</#if>
<#recover>Error</#attempt>
</#list>
<#-- Field - Simple -->
${user}
<#-- Field - Repeatable -->
<#list listActions as action>
${action}
</#list>
</#if>
</#list>
</#if>

Liferay Freemarker - How to get tags in a Content Template

I have content with a structure and a template and I want to access the tags of the content to show it in the template.
In a previous Application Display Template of an Asset Publisher, i got the tags with the ServiceLocator like this:
<#list entries as entry>
<#assign assetEntryLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService") />
<#assign assetTagLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetTagLocalService") />
<#assign assetTags = assetTagLocalService.getEntryTags(entry.getEntryId()) />
<#list assetTags as tag>
<#if tag.getName() != "startseite">
${tag.getName()}
</#if>
</#list>
</#list>
In my Template, I swapped entry with .vars['reserved-article-id'].data but then I get an error:
Method public final java.util.List com.sun.proxy.$Proxy562.getEntryTags(long) throws com.liferay.portal.kernel.exception.SystemException threw an exception when invoked on com.liferay.portlet.asset.service.impl.AssetTagLocalServiceImpl#6bc73e2b
How do you get this to work in a template?
Tags are associated with the assetEntry using it's resourcePrimKey, so you can do this:
<#assign assetEntryLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService") />
<#assign journalArticleLocalService = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService") />
<#assign article = journalArticleLocalService.getArticle(getterUtil.getLong(scopeGroupId), .vars['reserved-article-id'].data)>
<#assign asset = assetEntryLocalService.getEntry('com.liferay.portlet.journal.model.JournalArticle', article.resourcePrimKey) >
<#list asset.getTags() as tag>
<code>${tag.name}</code>
</#list>
As of Liferay 7, you should be able to use the following:
<#list entries as entry>
<#assign
entry = entry
/>
<#list entry.tagNames as tag>
${tag}
</#list>
</#list>

How to get list of pages in WCM (Liferay)?

I tried to create a Web Content with a Template that contains the navigation (list of pages):
<nav id="navigation">
<ul>
<#list nav_items as nav_item>
<#assign nav_item_css_class = "" />
<#if nav_item.isSelected()>
<#assign nav_item_css_class = "selected" />
</#if>
<li class="${nav_item_css_class}">
${nav_item.getName()}
<#if nav_item.hasChildren()>
<ul class="child-menu">
<#list nav_item.getChildren() as nav_child>
<#assign nav_child_css_class = "" />
<#if nav_item.isSelected()>
<#assign nav_child_css_class = "selected" />
</#if>
<li class="${nav_child_css_class}">
${nav_child.getName()}
</li>
</#list>
</ul>
</#if>
</li>
</#list>
</ul>
</nav>
But I get this error:
Expression nav_items is undefined
In my theme navigation.ftl it works but in the WCM ftl (FreeMarker) doesn't work.
Then, how can I get the list of pages in WCM?
The list of pages is available only in ADTs (Application Display Templates), not in WCM templates.
If you really need the list and can use ADTs, use navItems variable instead. The variable nav_items only works in themes (for backward compatibility, I guess).
Documentation - hard to find. Use the force, read the source - on GitHub.
You may want to use a handy Freemarker script to display all available variables - see Dumping ADT+WCM Template Variables on James Falkner's blog.

Resources