Rendering Liferay Page URLs Inside Liferay 6.1 Portlets

I am new to liferay, and I'm pretty sure that it is simply impossible to do: using speed markup, I want to be able to create links to pages on my Liferay website and embed them inside my portlets to different pages,

I have a vague idea of ​​how this could be done, so I searched, believing that it would be sent somewhere, but I can not find anything on it. By the way, I want to put any code that I create inside the view.jsp portlet. I would use speed markup here, but I don’t think (I don’t know for sure) if this is allowed inside jsp.

Please let me know if you need more information for an answer.

+4
source share
2 answers

I would use speed markup here, but I don’t think (I don’t know for sure) if this is allowed inside jsp.

Why do you want to use Velocity markup inside JSP ( view.jsp )? I do not see any advantages in this, except for the argument that you are really healthy at speed.

Although there is a link that helps you embed speed inside the JSP.

Note. In my opinion, it’s not a good practice to embed speed in a JSP in a portlet

In JSP :

In VM (these would be *.vm files in themes):
You can follow the same steps as in JSP. What you need to do is:

  • A LayoutLocalService instance can be found using the following code (taken from this):

     #set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService")) 

    now you can use the speed variable $layoutLocalService to call maintenance methods to get layouts.

  • You can then call the methods of the PortalUtil class using the $portalUtil variable, available for *.vm files in themes.

You can check the following files for more information (if you're interested):

+4
source

For speed:

Okay, so to create links for Liferay pages in speed, take a look at the following file in the Liferay source code:

 /portal-web/docroot/html/themes/_unstyled/templates/navigation.vm 

Here you will see how the default Liferay theme creates a navigation structure for your site. To make your life easier, you can:

 <nav class="$nav_css_class" id="navigation"> <h1> <span>#language("navigation")</span> </h1> <ul> #foreach ($nav_item in $nav_items) #if ($nav_item.isSelected()) <li class="selected"> #else <li> #end <a href="$nav_item.getURL()" $nav_item.getTarget()><span>$nav_item.icon() $nav_item.getName()</span></a> #if ($nav_item.hasChildren()) <ul class="child-menu"> #foreach ($nav_child in $nav_item.getChildren()) #if ($nav_child.isSelected()) <li class="selected"> #else <li> #end <a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a> </li> #end </ul> #end </li> #end </ul> 

So Velocity scans the collection called $ nav_items, and then calls the getURL () method on each item to create the link.

For JSP:

  • You will need to use the LayoutLocalServiceUtil class and in particular one of the getLayouts () methods. You will need to choose the one that best suits your needs.
  • This will return a list of layouts (your pages), and then you can call getFriendlyURL () on each of these layouts to return its url This will be the relative URL of your site, so something like / My site-home-page.

Let me know if you have more questions!

+1
source

All Articles