EE 5.2.4
I'm developing a feature for custom analytics. Certain activities are saved as channel entries in order to be presented in a dashboard later.
I have the first part of the feature working. The way I've gone about it is to save the activity as a string of JSON in a channel entry field. My intention was to parse this out later, as I'm not sure what sort of technology I'll be using on the dashboard and JSON seemed like a universal/consistent format to store the data.
My issue is when I try to pass the JSON string as a tag parameter into a php class method, it doesn't like the JSON and returns nothing.
Example.
Template:
{exp:channel:entries channel='analytics' dynamic='no' status='not closed'}
{exp:class:my_method json='{json}'}
{/exp:channel:entries}
Class:
function my_method() {
$json = ee()->TMPL->fetch_param('json');
print_r($json);
}
When the {json}
is the saved JSON string from the channel (I know that's working because it shows just fine in the template), the $json
variable will return nothing, but if I replace {json}
in json='{json}'
with a normal string or even another entry field like {title}
it will work just fine and I'll get a correct print.
Any ideas what's happening to this JSON string?
I could use php to work with this data in the template, for example
<? php
$json = '{json}';
print_r(json_decode($json, true));
?>
but I'd really rather use the EE template features if possible because I just like them so much.
Thanks for your help!