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!
source share