Message Boards
How to make web content variables global? (on web page)
How to make web content variables global? (on web page)
Junior Member Posts: 44 Join Date: 12/18/19 Recent PostsHi!
I have two web content portlets on the page.
First includes
variable, for example, 'name'
The question is how to get (read) that variable if I need it inside
the second portlet that does not have access to the first portlet
variables?
Need somehow share variables between portlets, make
them global on the web page...
Could someone help me, please?
I use LR 7.0
RE: How to make web content variables global? (on web page)
Expert Posts: 449 Join Date: 5/26/15 Recent PostsIf it's not sensitive data for a quick and dirty hack you could use the HTML web storage feature to store a value from one portlet to retrieve in another. Probabbly with a DIV. You could use jQuery to quickly append the value into the receiving DIV. You can then say detect if the local storage is already filled and of the same value to avoid repeating the copy again.
https://stackoverflow.com/questions/40791207/setting-and-getting-localstorage-with-jquery
Or do the same using standard Javascript
https://blog.logrocket.com/localstorage-javascript-complete-guide/
Esentially you're copying one part of the DOM to the other so you could try this on a test html page on your desktop and open in the browser without doing it in Liferay. Once you got it going copy the storing bit in the first web content template and the retriving bit in the second web content.