Problems, need help? Have a tip or advice? Post it here.
4 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 :)
active topics, google
Free support is never free.. Donate!
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:

Code: Select all
<cms:func 'html_decode' str='' ><cms:ignore>

    // Converts HTML entities to chars
    // Sample to call this snippet:
    // <cms:call 'html_decode' str='&quot;firstname&quot;' />
    // <cms:call 'html_decode' str=my_text_editable />

    </cms:ignore>
    <cms:php>
        global $CTX, $FUNCS;
        $string = trim( $CTX->get('str') );
        if( strlen($string) == 0 ) return;

        echo $FUNCS->unhtmlentities( $string, 'UTF-8' );
    </cms:php>
</cms: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>
active topics, google
Free support is never free.. Donate!
TY!! :D :D :D
4 posts Page 1 of 1

Who is online

In total there are 7 users online :: 0 registered, 0 hidden and 7 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 7 guests