Search code examples
jsonexpressionengine

ExpressionEngine plugin return json data


In the plugin I use:

$this->return_data = json_encode(array('loggedin' => $LoggedIn, 'Cust_ID' => $Participant_ID));

In the template I call it like this

$custinfo = {exp:user_loggedin};

It returns it like this:

$custinfo = {"loggedin":"no","Cust_ID":-1};

And I get this error:

PHP Parse error:  syntax error, unexpected '{' in expressionengine/libraries/Functions.php(642) : eval()'d code on line 656

If I use

$custinfo = json_decode({exp:user_loggedin})

I get this error:

PHP Parse error:  syntax error, unexpected '{', expecting ')' in expressionengine/libraries/Functions.php(642) : eval()'d code on line 656

Any ideas??


Solution

  • My guess is that you need to quote your variable:

    $custinfo = "{exp:user_loggedin}";