Liferay how to show the top navigator for normal user năm 2024

Building portals, navigation naturally becomes an important building block of your implementation. Liferay comes with great support for navigation as is – the absolutely most common way of implementing navigation in a Liferay portal is to iterate through the top site pages in the theme [Velocity or FreeMarker] and using the Navigation Portlet for secondary navigation. Sometimes, however, your site requires navigation that is not covered through the existing means of navigating a Liferay portal. In our projects we have used numerous ways to handle different navigation scenarios. This is the first entry in a series of posts where I plan on expanding further on some of these examples.

Grouped Navigation

On a recent project, we had a design that implemented business areas in the normal main navigation in a slightly different way than other pages:

The business areas were to be placed in the main navigation, but should be grouped to the left of the other links. Also, the client wanted the ability to change names and friendly URLs of the business areas, and add/remove business areas.

To cater for this, we grouped the business areas into one page that we named “Business Sections” with the friendly URL “/business-sections”:

  • Business Sections [/business-sections, hidden]
    • Business Area 1 [/business-area-1, visible]
    • Business Area 2 [/business-area-2, visible]

The main page was set as hidden so that it was not included in the normal iteration of pages in navigation.vm in the theme. Also, the page type was set as “link-to-page”, linked to the first child page [Business Area 1]. Thus, if someone happens to hit the URL “../business-sections”, they would be sent to the page for “Business Area 1”. In navigation.vm in the theme, logic was added that pulls all the child pages of the page with the friendly URL “/business-sections” [using Liferay services from the theme] and displays them before the normal page iteration loop. Also, the last list item of the business-section-pages was given a CSS class that would allow for an extra margin.

Here is an example of the code in Velocity:

## Define variables [in init_custom.vm]

## Null variable

`

set[$null = $some-never-used-variable-name]`

## Url prefix

`

set[$url_prefix = ""]`

`

if[$layout.isPrivateLayout[]]`

`

set[$url_prefix = "/group"]`

`

else`

`

set[$url_prefix = "/web"]`

`

end`

`## Null variable`0

`## Null variable`1

`## Null variable`2

`## Null variable`3

`## Null variable`4

`## Null variable`5

`## Null variable`6

`## Null variable`7

`

end`

`## Null variable`9

`

set[$null = $some-never-used-variable-name]`0

`

set[$null = $some-never-used-variable-name]`1

`

set[$null = $some-never-used-variable-name]`2

`

set[$null = $some-never-used-variable-name]`3

`

set[$null = $some-never-used-variable-name]`4

`

set[$null = $some-never-used-variable-name]`5

`

set[$null = $some-never-used-variable-name]`6

`

set[$null = $some-never-used-variable-name]`7

`

set[$null = $some-never-used-variable-name]`8

`

set[$null = $some-never-used-variable-name]`9

`## Url prefix`0

`## Url prefix`1

`## Url prefix`2

`## Url prefix`3

`## Url prefix`0

`## Url prefix`5

`## Url prefix`6

`## Url prefix`7

`

end`

Now, this should work fine. But what if we are using a virtual host on the page? We could just emit the $url_prefix parameter in the url. But this is not a solution we were satisfied with. We wanted the navigation to work no matter if a virtual host was used or not. So we added the following check when setting the $url_prefix in init_custom.vm:

`## Url prefix`9

`

set[$url_prefix = ""]`0

`

set[$url_prefix = ""]`1

`

set[$url_prefix = ""]`2

`

set[$url_prefix = ""]`3

`

set[$url_prefix = ""]`4

`

end`

`

set[$url_prefix = ""]`

`

set[$url_prefix = ""]`7

`

set[$url_prefix = ""]`8

`

set[$url_prefix = ""]`9

`

if[$layout.isPrivateLayout[]]`0

`

if[$layout.isPrivateLayout[]]`1

`## Url prefix`0

`

if[$layout.isPrivateLayout[]]`3

`

end`

Now the navigation works in both cases. When there is no virtual host, the URL prefix [for example /web/guest] is added to the URL. When there is no virtual host, the prefix is omitted.

Although the scenario you’re facing might not be exactly the same as the one I’m covering above, I hope my examples will provide you with some valuable insights that can help you on your way.

How do I change the navigation menu in Liferay?

Configuring Navigation Menu Type.

Open the Site Menu [ ] and navigate to Site Builder → Navigation Menus..

Click Actions [ ] for the desired menu..

Select the desired navigation type: Primary Navigation, Secondary Navigation, or Social Navigation. Once selected, each menu's configuration appears in the Marked As column..

How do I get a friendly URL in Liferay?

Follow these steps to create friendly URLs:.

Create friendly URL routes. Create a routes. ... .

Provide an implementation of the FriendlyURLMapper service. Create a component that specifies a FriendlyURLMapper service, with two properties: ... .

Implement the FriendlyURLMapper service..

What is product navigation?

Product navigation is a horizontal view of the company navigation. Both the product navigation and the company navigation display the same information about the manufacturer. In the product navigation area a Drill down technique is used for easy navigation.

Chủ Đề