Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Working with JSON and CouchCMS, this works as posted in forums:

Code: Select all
<cms:capture into='persons' is_json='1' >
[ { "firstname":"Marilyn", "lastname":"Monroe" } , { "firstname":"Abraham", "lastname":"Lincoln" } , { "firstname":"Christopher", "lastname":"Columbus" } ]
</cms:capture>

<cms:show persons as_json='1' /><br>

<cms:each persons as='person' >
   <cms:show person.firstname /> <cms:show person.lastname /> <br />
</cms:each>


If I take the json string:

Code: Select all
[ { "firstname":"Marilyn", "lastname":"Monroe" } , { "firstname":"Abraham", "lastname":"Lincoln" } , { "firstname":"Christopher", "lastname":"Columbus" } ]


Manually save it into a template editable text area via couch admin, then modifying the above code to work in <cms:pages> to repeat the functionality from DB but does not work.

Code: Select all
<cms:pages masterpage='sample.php' id='554' >
   <!-- shows string correctly -->
   <cms:show json_string />

   <cms:capture into='persons' is_json='1' ><cms:show json_string /></cms:capture>

   <!-- this shows nothing -->
   <cms:show persons as_json='1' /><br>

   <cms:each persons as='person' >
      <cms:show person.firstname /> <cms:show person.lastname /> <br />
   </cms:each>

</cms:pages>


What am I missing?
I retested your sample code and apparently you are missing this -
<cms:editable name='json_string' type='textarea' no_xss_check='1' />


You can view-source in browser to see that visible quotes were HTML Entities before that change :)
If one can not use no_xss_check parameter in backend or maybe prefers a 'text' field over 'textarea' (regular 'text' fields do not support 'no_xss_check'), I just wrote a simple decoding func:

Sample usage would be like -
Code: Select all
<cms:capture into='persons' is_json='1' ><cms:call 'html_decode' str=json_string /></cms:capture>
TY!! :D :D :D
I am trying to set a JSON data as follows but it's not working:
Code: Select all
<cms:capture into='my_data' is_json='1'>
       
[
      <cms:pp_cart_items>       
          {
             "product_image" : <cms:escape_json><cms:show product_thumb /></cms:escape_json>,
             "product_name" : <cms:escape_json><cms:show title /></cms:escape_json>,
             "product_id" : <cms:escape_json><cms:show id /></cms:escape_json>,
             "product_qty" : <cms:escape_json><cms:show quantity /></cms:escape_json>,
             "product_line_total" : <cms:escape_json><cms:pp_config 'currency_symbol' /><cms:number_format line_total /></cms:escape_json>
            }<cms:if "<cms:not k_paginated_bottom />" >,</cms:if>
        </cms:pp_cart_items>

  ]         
       
</cms:capture >

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


However when I set the data explicitly like this it works:
Code: Select all
<cms:capture into='persons' is_json='1' >
[ { "firstname":"Marilyn", "lastname":"Monroe" } , { "firstname":"Abraham", "lastname":"Lincoln" } , { "firstname":"Christopher", "lastname":"Columbus" } ]
</cms:capture>

<cms:show persons as_json='1' /><br>
That code is not working, because k_paginated_bottom variable is not set by pp_cart_items tag. Take a look at the correct JSON listing template here viewtopic.php?f=8&t=8602 and copy the code that was used to put commas between items.
6 posts Page 1 of 1
cron