On Tue, Nov 29, 2011 at 5:06 PM, Dave <hunkyb...@gmail.com> wrote: > Hi, > > I have created a fairly huge JSON representation of a data structure. > That JSON resides in a template's Javascript. My template thus renders > fine. > > Turns out that since this is a CMS, the client will want to edit the > data structure. Add new elements, change existing ones etc. What would > be the Radiant Pattern that could be used to deal with this? > > - If the JSON is generated dynamically, is that best done with a > plugin of some kind? > - To provide for CRUD on this data, of which there are hundreds of > objects, what would be the best approach? > > As an example... I want the client to be able to upload a new logo > whenever they want, to their collection of logos. And each logo > collected has some other attributes like title, associate, etc.. > > I guess I am just looking for pointers as to how Radiant can be used > to serve up pages, where the pages render JSON, but that JSON is > editable using the Administration capabilities of Radiant. > > Thanks for any tips!! >
Hey Dave, In the future, I'd like to be able to have pages render differently for different MIME types but for now here's what you could do... You can create a Layout that renders with the required content type and then create a Page that acts as the endpoint which will serve up the JSON. Depending on how you need to lay this out you could put the code for the looping (and any other logic) in your Layout or in your Page (or Snippet, or wherever). What Radiant doesn't currently have is support to escape text for JSON output. I had a project where I needed this and wrote a tag "escape_json" (or something). I'll see if I can find that code. If you write a tag like this, I think it makes sense to be in the core. So a well-tested tag would easily be accepted. Does all of that make sense or should I elaborate on some part? -Jim -- Write intention revealing code #=> http://www.clean-ruby.com Jim Gay Saturn Flyer LLC 571-403-0338