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.

ExpressionEngine to output an array

January 19, 2011 10:16pm

Subscribe [2]
  • #1 / Jan 19, 2011 10:16pm

    Jabbler

    59 posts

    Hi guys, am having a bit of trouble getting EE to output a Javascript array for me.

    Here is the code am using

    var realId=new Array(
    {exp:channel:entries category="1" channel="designs"}
    {if listing_img !=""} //Make sure the field is not empty
    "{entry_id}"
    <? //Add a comma if not last result
        $counter = {count}; 
        $total = {total_results}; 
        if ($counter != $total){
            echo ",";
        }; 
    ?>
    {/if}
    {/exp:channel:entries});

    Expected Output

    var realId=new Array("1011", "1012", "1013");

    Generated Output

    var realId=new Array({if "filedir_2large_corpid.png" !=""}"24"
        ,{/if}{if "" !=""}"12"
        ,{/if}{if "" !=""}"11"
        ,{/if}{if "" !=""}"10"
        ,{/if}{if "" !=""}"9"
        ,{/if}{if "" !=""}"8"
        ,{/if}{if "" !=""}"7"
        {/if});

    EE: v2.1.3

    Plugins installed: FF Matrix, ImageSizer, Low Replace

    Template Setting:
    Type: Webpage
    Enable Caching: No
    Refresh Interval: 0
    Allow PHP? Yes
    PHP Parsing Stage: Output

  • #2 / Jan 20, 2011 6:13am

    Jabbler

    59 posts

    Solved, this is code I used in the end

    var realId=new Array({exp:channel:entries category="1" channel="designs" search:listing_img="not IS_EMPTY"}"{entry_id}"<? $counter = {count}; $total = {total_results}; if ($counter != $total){echo ",";}; ?>{/exp:channel:entries});
  • #3 / Jan 20, 2011 6:17am

    Ingmar

    29245 posts

    Excellent. Please post again in case there’s anything else.

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

ExpressionEngine News!

#eecms, #events, #releases