Forums de discussion

Page title from a link to layout

thumbnail
Matías Javier Elola, modifié il y a 11 années.

Page title from a link to layout

New Member Publications: 6 Date d'inscription: 12/01/10 Publications récentes
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

<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


#foreach($Enlace in $Enlaces.getSiblings())
<a href="$Enlace.getUrl()">THE_TITLE_HERE</a>
#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, modifié il y a 11 années.

RE: Page title from a link to layout

Regular Member Publications: 111 Date d'inscription: 13/03/08 Publications récentes
Tyr THE_TITLE_HERE = $Enlace.getTitle()
thumbnail
Tejas Kanani, modifié il y a 11 années.

RE: Page title from a link to layout (Réponse)

Liferay Master Publications: 654 Date d'inscription: 06/01/09 Publications récentes
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,


#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
#foreach($Enlace in $Enlaces.getSiblings())
        #if($validator.isNotNull($Enlace.getData()))
	        #set($currentLayout = $layoutLocalService.getLayout($getterUtil.getLong($groupId),false,$getterUtil.getLong($Enlace.getData())))
	        <a href="$Enlace.getUrl()">$currentLayout.getName()</a>
         #end
#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.

journal.template.velocity.restricted.variables=


I hope this will help you.

Regards,
TK
thumbnail
Matías Javier Elola, modifié il y a 11 années.

RE: Page title from a link to layout

New Member Publications: 6 Date d'inscription: 12/01/10 Publications récentes
Thanks a lot Tejas Kanani, it works!
Thank you very much for the sooner answer.
thumbnail
Kushal Jayswal, modifié il y a 10 années.

RE: Page title from a link to layout

New Member Publications: 18 Date d'inscription: 19/11/12 Publications récentes
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.

journal.template.velocity.restricted.variables=



How to add above lines into someLayout.tpl?
thumbnail
Tejas Kanani, modifié il y a 10 années.

RE: Page title from a link to layout

Liferay Master Publications: 654 Date d'inscription: 06/01/09 Publications récentes
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
#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
#foreach($Enlace in $Enlaces.getSiblings())
        #if($validator.isNotNull($Enlace.getData()))
            #set($currentLayout = $layoutLocalService.getLayout($getterUtil.getLong($groupId),false,$getterUtil.getLong($Enlace.getData())))
            <a href="$Enlace.getUrl()">$currentLayout.getName()</a>
         #end
#end

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

Thanks,
Tejas
thumbnail
Kushal Jayswal, modifié il y a 9 années.

RE: Page title from a link to layout

New Member Publications: 18 Date d'inscription: 19/11/12 Publications récentes
I wanted to get HTML title of the page and use the same to generate a dynamic class. But I got the solution.

Thanks.