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
RE: How to make web content variables global? (on web page)
Hi!
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
If 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.
Powered by Liferay™