Forum for discussing general topics related to Couch.
17 posts Page 1 of 2
Hi to all

Simple question:
inside a backend template, if I have a variable set by javascript like
<script>
let x = 5;
let y = 6;
let z = x + y;
</script>

How can I pass this 'z' value result to couchCMS?

I'm trying to use pure javascript to do some calculations, and communicate
1/ CouchCMS variable values to javascript,
2/ and return javascript result to CouchCMS


Are there some examples out there for those 2 topics?
Ok, just realize that my question could be confusing as javascript is supposed to run client side :)

But as I'm running node.js with php, I have both running server side

by the way, find out another way to do it with javascript workers and couchCMS

thanks
Can you share your solution, please?

I have the same problem.
@PaoloE, please share your JS as well as the PHP code with details on the kind of interaction you desire.
Hi KK,

I didn't want to bother you.

I got a cookie for my language like:

Code: Select all
<script>var langshop = getCookie("toggleLanguage");
if (langshop == "German") {langcart = 7};
if (langshop == "French") {langcart = 8};
if (langshop == "English") {langcart = 0};
</script>


I extract the cookie with
Code: Select all
<script>document.writeln(langcart);</script>


but when I do

Code: Select all
<cms:set language = "<script>document.writeln(langcart);</script>" />


and try to get my value in php

Code: Select all
echo '
<cms:show language />


it shows not the cookie value, but the JS <script>

What I need to do is the have the variable "Language" set to the cookie value.

I am not sure I actually make sense....

Thanks for your help
I tried to pass the variable from the cookie to php without success

Code: Select all
<script>var langshop = getCookie("toggleLanguage");
if (langshop == "German") {langcart = 7};
if (langshop == "French") {langcart = 8};
if (langshop == "English") {langcart = 0};
</script>

<cms:set language = '<script>document.writeln(langcart);</script>' />

<cms:php>
$language = '<cms:show language />';


Once the page is processed by php, I get the <script> details, not the value.
Paolo, the JS code (i.e. that within <script> tags) is executed in the browser while Couch code e.g. <cms:set language> is executed on the server. So it is not surprising that the two are not in sync.

I assume you are trying to run some logic on the server (i.e. Couch) based on the value of the 'toggleLanguage' cookie.
To do that, you may use the Couch tags pertaining to cookies -
<cms:get_cookie>
<cms:set_cookie>
<cms:delete_cookie>

Please try and let me know if you happen to need any help with it.

Hope this helps.
What I need is to retrieve the cookie that is set by the language tool.

I do not need to create cookies.
What I need is to retrieve the cookie that is set by the language tool.

The <cms:get_cookie> tag mentioned above does just that. Please try using it.
OMG.

I tried but without success, I didn't get it.

in fact, with

Code: Select all
<cms:get_cookie 'toggleLanguage' />

<cms:show toggleLanguage />


the cookie becomes a couch variable on its on.

Genius.

Thank you KK
17 posts Page 1 of 2