Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
How to customize the content of navigation menu in Liferay
Hi Experts,
I am working on a portal project using Liferay 7 GA4. How can I customize the navigation menu?
I have checked navigation.ftl in a theme project and there is a section for showing the menu.
After some googling, hook may be a direction. However, it is also said that OSGi module is the preferable way for customization.
Therefore, here is the question:
Which jsp is being used to control the behavior of com.liferay.site.navigation.menu.web OSGi module?
All the best,
Karl Chin
I am working on a portal project using Liferay 7 GA4. How can I customize the navigation menu?
I have checked navigation.ftl in a theme project and there is a section for showing the menu.
<@liferay.navigation_menu
instance_id="main_navigation_menu"
default_preferences="${freeMarkerPortletPreferences}"
/>
After some googling, hook may be a direction. However, it is also said that OSGi module is the preferable way for customization.
Therefore, here is the question:
Which jsp is being used to control the behavior of com.liferay.site.navigation.menu.web OSGi module?
All the best,
Karl Chin
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
I don't know if I understand your question...but try also to check site_pages.ftl
Hi Massimo,
I cannot find site_pages.ftl in the source. Where is the file location? under ../templates? Could you please provide some sample code on that?
TIA.
All the best,
Karl Chin
I cannot find site_pages.ftl in the source. Where is the file location? under ../templates? Could you please provide some sample code on that?
TIA.
All the best,
Karl Chin
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
Hi,
I guess I found it in a theme called atrek and the file is "sitepages.ftl"
put it inside templates folder
I guess I found it in a theme called atrek and the file is "sitepages.ftl"
put it inside templates folder
<h2><span>Site Pages</span></h2>
<ul>
<#assign count = 0 />
<#list nav_items as nav_item>
<#assign count = count +1 />
<#assign nav_item_class = "item-" + count />
<#if count == 1>
<#assign nav_item_class = nav_item_class + " first" />
<!--#if-->
<#if nav_item.isSelected() >
<#assign nav_item_class = nav_item_class + " selected" />
<!--#if-->
<li class="${nav_item_class}">
<a href="${nav_item.getURL()}" ${nav_item.gettarget()}>
<span>${nav_item.getName()}</span>
</a>
</li>
<#if nav_item.hasChildren()>
<#list nav_item.getChildren() as nav_child>
<#if nav_item.isSelected()>
<li class="selected sub">
<#else>
</li><li class=" sub">
<!--#if-->
<a href="${nav_child.getURL()}" ${nav_child.gettarget()}>${nav_child.getName()}</a>
</li>
<!--#list-->
<!--#if-->
<!--#list-->
</ul>
Hi Massimo,
Thanks for your code.
Can I just change some .js to fulfill the customization on the content of the navigation menu? Actually, I am trying to search in the source but not yet identified which one does the work.
All the best,
Karl Chin
Thanks for your code.
Can I just change some .js to fulfill the customization on the content of the navigation menu? Actually, I am trying to search in the source but not yet identified which one does the work.
All the best,
Karl Chin
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
I have never overide liferay JS, I only added some function inside my code.
Try to write your function and add it inside your sitepage.ftl otherwise you can search on google how to insert your js file in liferay
Try to write your function and add it inside your sitepage.ftl otherwise you can search on google how to insert your js file in liferay
Hi Massimo,
You code in sitepages.ftl will work on web, however, it is still not mobile responsive.
I can see there is a code in navigation.ftl.
I am wondering if we can customize it (liferay.navigation_menu)?
I can only see some guideline on the customization of product menus. (https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/product-navigation)
All the best,
Karl Chin
You code in sitepages.ftl will work on web, however, it is still not mobile responsive.
I can see there is a code in navigation.ftl.
<@liferay.navigation_menu
instance_id="main_navigation_menu"
default_preferences="${freeMarkerPortletPreferences}"
/>
I am wondering if we can customize it (liferay.navigation_menu)?
I can only see some guideline on the customization of product menus. (https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/product-navigation)
All the best,
Karl Chin
Massimo Bevilacqua, modified 8 Years ago.
Regular Member
Posts: 210
Join Date: 12/27/16
Recent Posts
Hi,
are you sure it is not responsive?I use sitepages in my theme and it is responsive.
By the way if you need to customize navigation menu you can change navigation.ftl, sitepages.ftl and put your css style inside _custom.scss.
My suggestion is: take an existing free theme (porygon or 1975 London) and look inside the code(templates, css....) in this way you can understand how customize navigation menu(in porygon theme you can find _header.scss and _navbar_porygon.scss).
Best regards
Massimo
are you sure it is not responsive?I use sitepages in my theme and it is responsive.
By the way if you need to customize navigation menu you can change navigation.ftl, sitepages.ftl and put your css style inside _custom.scss.
My suggestion is: take an existing free theme (porygon or 1975 London) and look inside the code(templates, css....) in this way you can understand how customize navigation menu(in porygon theme you can find _header.scss and _navbar_porygon.scss).
Best regards
Massimo
Hi Massimo,
Yes, you are right. Your code is responsive to mobile.
Therefore, together with what's in https://web.liferay.com/community/forums/-/message_boards/message/94161220, I have add the following code in sitepages.ftl in the templates folder in a custom theme to customize my navigation menu.
Also remember to apply the sitepages.ftl in portal_normal.ftl by changing the code like:
You really save my day, thank you very much! Expert!
All the best,
Karl Chin
Yes, you are right. Your code is responsive to mobile.
Therefore, together with what's in https://web.liferay.com/community/forums/-/message_boards/message/94161220, I have add the following code in sitepages.ftl in the templates folder in a custom theme to customize my navigation menu.
<div aria-expanded="true" class="collapse navbar-collapse" id="navigationCollapse">
<ul class="nav navbar-nav">
<#assign count = 0 />
<#list nav_items as nav_item>
<#assign count = count +1 />
<#assign nav_item_class = "item-" + count />
<#if count == 1>
<#assign nav_item_class = nav_item_class + " first" />
<!--#if-->
<#if nav_item.isSelected() >
<#assign nav_item_class = nav_item_class + " selected" />
<!--#if-->
<li class="${nav_item_class}">
<a href="${nav_item.getURL()}" ${nav_item.gettarget()}>
<span>${nav_item.getName()}</span>
</a>
</li>
<#if nav_item.hasChildren()>
<#list nav_item.getChildren() as nav_child>
<#if nav_item.isSelected()>
<li class="selected sub">
</li>
<#else>
<li class="sub">
<!--#if-->
<a href="${nav_child.getURL()}" ${nav_child.gettarget()}>${nav_child.getName()}</a>
</li>
<!--#list-->
<!--#if-->
<!--#list-->
<#assign linkUrl = themeDisplay.getPortalURL() />
<#assign screenName = themeDisplay.getUser().screenName />
<li class="${nav_item_class}">
<a href="${linkUrl}/user/${screenName}">My Dashboard</a>
</li>
<li class="${nav_item_class}">
<a href="${linkUrl}/web/lportal/sign-out">Sign Out</a>
</li>
</ul>
</div>
Also remember to apply the sitepages.ftl in portal_normal.ftl by changing the code like:
<#if has_navigation>
<#--include "${full_templates_path}/navigation.ftl" /-->
<#include "${full_templates_path}/sitepages.ftl" />
<!--#if-->
You really save my day, thank you very much! Expert!
All the best,
Karl Chin