RE: RE: How can I import Liferay Portal library to my react project?

Jamie Sammons, modified 2 Years ago. New Member Posts: 6 Join Date: 3/9/23 Recent Posts

Hello everyone, i would like to use the command Liferay.ThemeDisplay in my react application but if i try to install the library liferay-portal or frontend-js-web with npm I get errors, so i tried to install directly from github with the command npm install https://github.com/liferay/liferay-portal but is still not working.

I searched on the net and the library that i have to use should be this one, so how can i add to my react application?


Thanks everyone.

thumbnail
Jamie Sammons, modified 2 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts

The Liferay object is added to all Liferay pages as a global variable, so you should be able to just access it directly when your React application is added to a Liferay page. No need to import anything.

Jamie Sammons, modified 2 Years ago. New Member Posts: 6 Join Date: 3/9/23 Recent Posts

I've already tried to use it without import anything but it didn't work. I have the error 'Liferay’ is not defined that's why i thought i had to import something. How can I solve this error? Thanks.

thumbnail
Jamie Sammons, modified 2 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

Try using window.Liferay.ThemeDisplay.

Jamie Sammons, modified 2 Years ago. New Member Posts: 6 Join Date: 3/9/23 Recent Posts

Already tried, still not working unfortunately.

Jamie Sammons, modified 2 Years ago. New Member Posts: 6 Join Date: 2/8/23 Recent Posts

Hi Gregorio,

in Liferay Github you can find some examples how it works. As I unterstand you try to run something like coded in this client extension:

https://github.com/liferay/liferay-portal/tree/master/workspaces/liferay-sample-workspace/client-extensions/liferay-sample-custom-element-2