Fórumok

How get a Javascript variable value from Freemarker?

Norman Sánchez, módosítva 9 év-val korábban

How get a Javascript variable value from Freemarker?

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2013.09.24. Legújabb bejegyzések
Hello, everybody,
I'am trying to show only an element in a structure template getting a posted url var.
If 'p' is the posted variable, How can I evaluated her value in Freemarker?


<script>
    p=4;
</script>
&lt;#if p==4&gt;
    <p>p=4</p>
&lt;#else&gt;
    <p>p!=4</p>
<!--#if-->


Can I access to a posted varible directly from Freemarker?
thanks a lot!
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: How get a Javascript variable value from Freemarker?

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Um, JavaScript is running in the browser, not the server. Freemarker is running in the server, not in the browser. They really are not connected in this way.

It may be confusing in that you can code your JS into your FM template, but they have completely different execution contexts.
Norman Sánchez, módosítva 9 év-val korábban

RE: How get a Javascript variable value from Freemarker?

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2013.09.24. Legújabb bejegyzések
Thank you, David,

Ok, then... I'll can get tha variable from the url or from a session variable? Or the template is loaded on the page before the call?
I've an structure with some elements and I only want to show one of them... I thought that I can get a variable from the URL and filter the element that I want to show....
How can I do it? It's not wll defined? If I have a template based in a structure I have to show all the elements?

Somethink like this
I get the same error request.getParameter("var") is undefined.

Thank you so much!
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: How get a Javascript variable value from Freemarker?

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
The parameters may be there, but the reference you point at is checking whether they are there or not.

The part that is missing is that often times the parameters will be namespaced, so you won't find a simple 'var' but it will have a lot more in front of it.
Norman Sánchez, módosítva 9 év-val korábban

RE: How get a Javascript variable value from Freemarker?

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2013.09.24. Legújabb bejegyzések
But I always know wich is the link format.
I have a lot of links to the same page only changing the variable that I send:
- http://mypage.html?q=1
- http://mypage.html?q=2
- http://mypage.html?q=3
- http://mypage.html?q=4
- http://mypage.html?q=5
-....

I want, in freemarker, get the var q and compare with the elements of my structure for only show one of them.
I want to have all the content grouped in my structure...I don't know if it's a good idea.

I also have developed a portlet for have this utility but I've the problem that I don't know if I could show the content from search portal engine...
Too many questions, I know.... I don't know wich solution is better, still I don't know if it's possible...

Sorry and thanks!
thumbnail
Dave Weitzel, módosítva 9 év-val korábban

RE: How get a Javascript variable value from Freemarker?

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2009.11.18. Legújabb bejegyzések
You should be able to get to the request parameters in Freemarker, as the request object is there (as a JSON type object).
Or a number of the request utilities are available.

I would use assetQueries to retrieve objects from the system in your templates setting the contains does not contain categories but a lot depends on teh detail of your requirement