RE: RE: Theme Search Bar destination search page configuration.

Olaf Kock, modified 1 Year ago. New Member Posts: 3 Join Date: 1/4/24 Recent Posts

Hi everyone.

liferay version : portal-7.4-ga99

I want to customize search page without search page template.So I have a search bar injected in my theme header in the following way :

<#assign search_preferences = freeMarkerPortletPreferences.getPreferences({"portletSetupPortletDecoratorId": "barebone", "destination": "/search-page"}) /> <@liferay.search_bar default_preferences="${search_preferences}" />

I passed destination param to redirect to my custom search page which has "/search-page" friendly url.


But when I hit the search button , I've been redirected to default search page. So I decided to try add search bar widget manually and set destination page to "/search-page" , it works fine.

What I aslo noticed is that this search bar has portletId : com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet_INSTANCE_ibds
and my theme search bar is different somehow : com_liferay_portal_search_web_portlet_SearchPortlet_INSTANCE_templateSearch
Even though I see that under @liferay.search_bar lays portletProviderClassName="com_liferay_portal_search_web_search_bar_portlet_SearchBarPortlet" property
 

What am I missing here ? How can I also remove my current theme search bar and replace it with a new one if I'd have to (as I tested , it's not being updated when I change destination preference in it) ? Thanks. 

thumbnail
Olaf Kock, modified 1 Year ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

I'd recommend to drop the old habit of injecting portlets into pages or layout templates, and rather go through the UI with Content Pages and Master Pages. This is so much more interactive, no need to develop or deploy anything.

That being said, to debug what you currently have: This project/plugin might help you identify the required preferences. It's an ugly UI, but shows what is currently configured.

If I recall correctly, those preferences will be stored with the page the first time you view the page. To update them, you'd have to get rid of the existing preferences using the API, or change the instance id. Another reason why Master Pages are so much more comfortable.

Olaf Kock, modified 1 Year ago. New Member Posts: 3 Join Date: 1/4/24 Recent Posts

Thanks , I used this aproach (change instance id) with @liferay.navigation_menu , but unfortunately @liferay.search_bar macro doensn't have such paramI also know that theme-less approach is a better solution , I just practising themes development as legacy project might have use it ...
Do you know which API can I use to get rid of the existing preferences ?

thumbnail
Olaf Kock, modified 1 Year ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

The API would be very similar to the API used in the linked plugin. Just writing instead of reading (be careful...)

As of "legacy use": You're upgrading anyway, and might as well get rid of legacy technique during the upgrade, to make your life easier.

Olaf Kock, modified 1 Year ago. New Member Posts: 3 Join Date: 1/4/24 Recent Posts

Not only my life , but other devs' too :)

Jamie Sammons, modified 8 Months ago. New Member Post: 1 Join Date: 8/20/24 Recent Posts

My Liferay version is Liferay DXP-2024.q3.0. I did the same thing today and it works for me.

<#assign preferences = freeMarkerPortletPreferences.getPreferences({"portletSetupPortletDecoratorId": "barebone", "destination": "/search"}) />
<@liferay.search_bar default_preferences="${preferences}" />

I don't think you need to add or edit any parameters since this code is the same as the source code of theme-classic. However, I have no clue why it doesn't work to you.