掲示板

Retrieve Page Title in Freemarker Web Content Template

8年前 に Silvio Meier によって更新されました。

Retrieve Page Title in Freemarker Web Content Template

New Member 投稿: 8 参加年月日: 14/05/06 最新の投稿
I tried to retrieve the title of the page for the current page in a freemarker web content template (Liferay 6.2), as done in
http://stackoverflow.com/questions/1923459/liferay-request-current-page-name

However the following code is not working:

<#assign themeDisplay = request['theme-display'] />
<#assign layout = themeDisplay.getLayout() />
<#assign title = layout.getName(locale) />


The code fails at the second line complaing the corresponding method is not found. How is it done actually?

Is there a more detailed description of accessing variables and internal structure from freemarker templates?
thumbnail
8年前 に Andew Jardine によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Silvio,

You could try using the service locator to retrieve the layout object based on the friendly url. In case you have not done this before, in your portal-ext.properties file make sure you have the following property set


freemarker.engine.restricted.variables=


This will make the serviceLocator available in your template for you to use. In your template you can then do this to get the Layout


<#assign isPrivateLayout = false />
<#assign friendlyURL = "/this/is/the/page/url" />
<#assign layoutService = serviceLocator.findService("com.liferay.portal.service.LayoutLocalService") />
<#assign layout = layoutService.fetchLayoutByFriendlyURL( getterutil.getLong(groupId, isPrivateLayout, friendlyURL) />
<#assign pageTitle = layout.getName(locale) />


Can you give that a shot and let us know if it works?
8年前 に Silvio Meier によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template (回答)

New Member 投稿: 8 参加年月日: 14/05/06 最新の投稿
Hi Andrew

thank you very much for your answer. It is a possible solution. In the mean time I found the solution that actually works for my case:
<#assign themeDisplay = request['theme-display'] />
<#assign layout = themeDisplay['plid'] />
<#assign layoutService = serviceLocator.findService("com.liferay.portal.service.LayoutLocalService") />
<#assign layoutObject = layoutService.getLayout(layout?number) />
<#assign pageTitle = layoutObject.getName(locale) />


One problem I have with Freemarker in Liferay is that Freemarker seems to be more poorly supported and used than velocity scripting, even though there is often the hint that freemarker is more powerful than velocity.

I had really troubles in finding documentation about variables and objects that are available in freemarker for Liferay templates. Fortunately I found this post of J. Falkner which provides a link to a script that lists all available variables and objects in a freemarker template scripts. This script helped me a lot.
thumbnail
8年前 に Andew Jardine によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Silvio,

I have that post from James bookmarked and reference it often. I was actually thinking about it as I read your original post but had more recently used the code I provided to you. Happy to hear that you have it working though emoticon
thumbnail
8年前 に Jack Bakker によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
Just getting more deeply into freemarker templates, and have now pdf reference of variables thanks to output from James' dump script. This is interesting stuff and can, in many cases replace need to create custom portlets... Cool !
thumbnail
8年前 に James Falkner によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Legend 投稿: 1399 参加年月日: 10/09/17 最新の投稿
Jack Bakker:
Just getting more deeply into freemarker templates, and have now pdf reference of variables thanks to output from James' dump script. This is interesting stuff and can, in many cases replace need to create custom portlets... Cool !



if any of you are at NAS next week ask me to show you the realtime web content freemarker template renderer thingy I hacked together for dev.live last week in London! You can quickly find out what works in Freemarker without having to edit/save/reload. It (sort of) autocompletes too! I'll eventually blog about it but am in NAS crazy-mode at the moment.
thumbnail
8年前 に Jack Bakker によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
James Falkner:

if any of you are at NAS next week ask me to show you the realtime web content freemarker template renderer thingy I hacked together for dev.live last week in London! You can quickly find out what works in Freemarker without having to edit/save/reload. It (sort of) autocompletes too!


now looking at my Android Liferay Events app on how to fit in the ad hoc "Corner James to demo template renderer thingy"... emoticon
thumbnail
8年前 に Andrew Jardine によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
I don't know if you caught up with James to see his "hack" that he uses, but I did and it was pretty cool. I think figuring out how to work that into a hook for now would be super helpful

@James -- did you say that it was available on github?
thumbnail
8年前 に Jack Bakker によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
Andrew Jardine:
I don't know if you caught up with James to see his "hack" that he uses, but I did and it was pretty cool. I think figuring out how to work that into a hook for now would be super helpful


hey Andrew, was good to see you and others at LRNAS2015... np for me that I didn't see James' thing tho cool ; I gather in context feedback for content managers and template developers will evolve
thumbnail
8年前 に Andrew Jardine によって更新されました。

RE: Retrieve Page Title in Freemarker Web Content Template

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Based on what we saw at the conference that is a definite. James' tool though I didn't see on the featureset or roadmap -- but it totally should be! I'd be willing to spend some time working on something that can be contributed to the marketplace for others!