ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

channel entries and javascript

May 04, 2011 3:41am

Subscribe [1]
  • #1 / May 04, 2011 3:41am

    cbad

    60 posts

    I’d like to initialize a json structure with channel entries. For the most part it seems to work fine, except for the last entry where you can’t have a comma ending it. It should look something like:

    table = [
    {"key": "one"},
    {"key": "two"},
    {"key": "three"}
    ];

    So I tried this code:

    table = [
    {exp:channel:entries channel="mychannel" }
        {"key": "{value}"}{if count!=total_results},{/if}
        {/exp:channel:entries}
    ];

    {value} is from mychannel. The first part of this works fine. The problem is with the conditional. It just prints out the conditional statement rather than evaluating it. So I get something like this for each of the entries:

    {"key": "two"}{if "2"!= "3"},{/if}

    Can I get this to work or is there some other way?

    Thanks!

  • #2 / May 04, 2011 3:37pm

    Kevin Smith

    4784 posts

    Hey cbad—

    Hmm… I’m not sure why that conditional isn’t being rendered, but I looked around to see how others in the community are outputting channel entries as JSON and found this post. Wouter uses PHP to accomplish the task and Rob Sanchez wrote a nice little plugin to do the job.

    Do either one of those work for you?

    Kevin

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases