Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Matías Javier Elola
Page title from a link to layout
June 21, 2012 9:24 AM
Answer

Matías Javier Elola

Rank: New Member

Posts: 6

Join Date: January 12, 2010

Recent Posts

Hello everybody!
I'm using the Liferay 6.1.0 bundle with JBoss 7 (under linux) and my intentions are to create different structures and templates for displaying web contents.
My problem is:

I've defined a structure with different elements and one of them is a link_to_layout and I want to display the element's title

1<dynamic-element name="Enlaces" type="link_to_layout" index-type="" repeatable="true"/>


As you can see, this is "repeatable", so, to get the information in the velocity template I have to use a foreach like the next one

1
2#foreach($Enlace in $Enlaces.getSiblings())
3<a href="$Enlace.getUrl()">THE_TITLE_HERE</a>
4#end


So, I have to show THE_TITLE_HERE based on the $Enlace.getUrl() page, it means that I want to show the title of each page I've linked in the content.

I am linking public pages of my own community

Can you help me please?

I was looking for the solution here but one of the options is creating a new velocity variable. I guess (and hope) it's easier than that.

Thanks!
Chintan Akhani
RE: Page title from a link to layout
June 21, 2012 10:30 PM
Answer

Chintan Akhani

Rank: Regular Member

Posts: 111

Join Date: March 13, 2008

Recent Posts

Tyr THE_TITLE_HERE = $Enlace.getTitle()
Tejas Kanani
RE: Page title from a link to layout
June 22, 2012 12:29 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

Hi Matías Javier Elola,

You'll have to use get it from layoutservice. For that you'll have to use serviceLocator.
Try below code,

1
2#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
3#foreach($Enlace in $Enlaces.getSiblings())
4        #if($validator.isNotNull($Enlace.getData()))
5            #set($currentLayout = $layoutLocalService.getLayout($getterUtil.getLong($groupId),false,$getterUtil.getLong($Enlace.getData())))
6            <a href="$Enlace.getUrl()">$currentLayout.getName()</a>
7         #end
8#end


And make sure you have added below property(with blank value) in portal-ext.properties. As by default you can't use serviceLocator in webcontent template. After adding below property it will allow you to use serviceLocator.

1journal.template.velocity.restricted.variables=


I hope this will help you.

Regards,
TK
Matías Javier Elola
RE: Page title from a link to layout
June 22, 2012 1:18 AM
Answer

Matías Javier Elola

Rank: New Member

Posts: 6

Join Date: January 12, 2010

Recent Posts

Thanks a lot Tejas Kanani, it works!
Thank you very much for the sooner answer.
Kushal Jayswal
RE: Page title from a link to layout
November 26, 2013 2:06 AM
Answer

Kushal Jayswal

Rank: New Member

Posts: 12

Join Date: November 18, 2012

Recent Posts

Tejas Kanani:
Hi Matías Javier Elola,

And make sure you have added below property(with blank value) in portal-ext.properties. As by default you can't use serviceLocator in webcontent template. After adding below property it will allow you to use serviceLocator.

1journal.template.velocity.restricted.variables=



How to add above lines into someLayout.tpl?
Tejas Kanani
RE: Page title from a link to layout
November 26, 2013 4:38 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

Which lines are you asking about the one that you've pointed ?
journal.template.velocity.restricted.variables=

If you are referring to this, it will be added in portal-ext.properties

And if you asking about
1#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
2#foreach($Enlace in $Enlaces.getSiblings())
3        #if($validator.isNotNull($Enlace.getData()))
4            #set($currentLayout = $layoutLocalService.getLayout($getterUtil.getLong($groupId),false,$getterUtil.getLong($Enlace.getData())))
5            <a href="$Enlace.getUrl()">$currentLayout.getName()</a>
6         #end
7#end

What exactly you want to do in your layout ? What is you requirement ?

Thanks,
Tejas
Kushal Jayswal
RE: Page title from a link to layout
May 6, 2014 3:50 AM
Answer

Kushal Jayswal

Rank: New Member

Posts: 12

Join Date: November 18, 2012

Recent Posts

I wanted to get HTML title of the page and use the same to generate a dynamic class. But I got the solution.

Thanks.