0

Some of my templates outputs JSON string, which was designed to be consumed by the frontend's JS. However, I also have the need to consume this JSON within my templates. Is there an add-on that I can use that takes a JSON string and converts it to loopable EE data? If not, how can I approach this problem?

  • What do you mean by the difference between consumed by the frontend JS and consumed by your templates? Does the template generate the json or is it just referenced and still need to go through a jQuery.getJSON() or jQuery.parseJSON() to use the data? – rchrdg Jul 4 '14 at 7:12
  • The template generates the JSON. When the JS calls that template, it can deal with the data since it's JSON. When a template embed that template that generates the JSON, can it iterate through that JSON data somehow? – ExpressionEngineNewbie Jul 4 '14 at 9:21
  • You could parse the JSON using jQuery.parseJSON or with just the default JSON.parse object in javascript. – rchrdg Jul 4 '14 at 9:39
-1

Here is an example of how you can parse JSON and then loop through the data and append html to the data and your DOM with JavaScript.

https://stackoverflow.com/questions/5715952/parsing-json-in-javascript-using-for-loop

| improve this answer | |
  • This was not a JS question. I want to use JSON within EE templates. – ExpressionEngineNewbie Jul 6 '14 at 4:42
  • "If not, how can I approach this problem?" that was the end of your question. and you can loop through your json data and output html markup around your json data with js in your template. Are you saying you want to parse your JSON data into template variable tags? If thats the case you will need to create a plugin that allows you to input your json code through a parameter and processes it via php and outputs your desired result into the template. – mattsidjohn Jul 6 '14 at 16:10
  • Right, the problem was how to use JSON within templates. – ExpressionEngineNewbie Jul 6 '14 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.