Foren
Retrieve Page Title in Freemarker Web Content Template
Silvio Meier, geändert vor 9 Jahren.
Retrieve Page Title in Freemarker Web Content Template
New Member Beiträge: 8 Beitrittsdatum: 06.05.14 Neueste Beiträge
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:
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?
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?
Andew Jardine, geändert vor 9 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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
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
Can you give that a shot and let us know if it works?
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?
Silvio Meier, geändert vor 9 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template (Antwort)
New Member Beiträge: 8 Beitrittsdatum: 06.05.14 Neueste Beiträge
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:
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.
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.
Andew Jardine, geändert vor 9 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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
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
Jack Bakker, geändert vor 8 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste Beiträge
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 !
James Falkner, geändert vor 8 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste BeiträgeJack 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.
Jack Bakker, geändert vor 8 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste BeiträgeJames 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"...
Andrew Jardine, geändert vor 8 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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?
@James -- did you say that it was available on github?
Jack Bakker, geändert vor 8 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste BeiträgeAndrew 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
Andrew Jardine, geändert vor 8 Jahren.
RE: Retrieve Page Title in Freemarker Web Content Template
Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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!