Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
5 posts Page 1 of 1
Hi @KK,

I am about to send a boolean in JSON response.
Code: Select all
{"response":true,"message":""}


I am using php to pass a boolean value to a variable, but since CouchCMS converts boolean true to string 1 while setting a variable's value - I can not achieve my goal easily.

I really don't want to write a 'form_status' array parser to replace 'true' to true or '1' to true. But I'd have to if you say there is no other way.
Hi,

Will this workaround do? -
Code: Select all
<cms:set form_status = '[]' is_json='1' scope='global' />
<cms:php>
    global $CTX;
    $CTX->set('form_status', array('response'=>true), 'global');
</cms:php>

<cms:show form_status as_json='1' />

Output:
Code: Select all
{"response":true}
To preserve existing values in the array, we can use this e.g. -
Code: Select all
<cms:set form_status='[]' is_json='1' scope='global' />
<cms:set form_status.test='hello' />

<cms:php>
    global $CTX;
    $arr = $CTX->get('form_status');
    $arr['response']=true;
    $CTX->set('form_status', $arr, 'global');
</cms:php>

<cms:set form_status.test2='hello2' />

<cms:show form_status as_json='1' />

Output:
Code: Select all
{"test":"hello","response":true,"test2":"hello2"}
It surely helps :) Ingenious solution. Please move to Tips&Tricks.
I'm glad it helped :)
5 posts Page 1 of 1
cron