A JSON file can sometimes be the answer to letting non-developers help you fill in standardized sections of a website and help you get an application out the door quickly.
I previously talked about how I leveraged using variables in queries to help with a site I was recently tasked to build. As a quick refresher each page on this site would look the same with a right sidebar with some definitions and descriptions, then a chart of data on the left, with a data table underneath to show the data in tabular form. In that previous post I was concerned with the survey data in the app and how to pull it out for display easily. This time I am worried about how to handle all of that text in the right sidebar. This sidebar would have a description of the data being presented, definitions for the data elements, and any other pertinent information my group wanted to display.
So the obvious answer, at least to me, is to create a simple CRUD (Create, Read, Update, Delete) app for users to enter that text and then pull it out as needed. In this case though we were under a time crunch to get the site out so I was trying to think of what would be the easiest and quickest idea to implement. Also, what would be relatively easy for the staff member responsible to update. These would not be developers. Finally, what would give me the flexibility to come back later, if I were given the time, to swap in a better and more elegant solution down the road. I had just been knee deep in some API work that was giving me a JSON file back and I thought that is about as simple as you get. I could work with it easily, it looks close enough to a text file for the staff member who’d handle the text, and I could swap in a service down the road to change the JSON source when I could circle back. Seems easy enough.
The first step was I just needed a sample JSON file to show people so they could just copy and paste it till their heart’s content.
{“Header 1”: “<p>Put any text you want under this header/section here</p><p>If you want multiple paragraphs just put them inside these p tags like this</p>”,“Header 2”: “<p>This is the text for the second header. Repeat this as much as necessary</p>”}
<!— Do we have a JSON sidebar file to work from? —><cfif fileExists(‘#ExpandPath( “./” )#assetssidebarJSON#metrics.sidebarJSONFile#’)><!— Pull in the contents —><cfset sidebarJSON = fileRead( ‘#ExpandPath( “./” )#assetssidebarJSON#rc.metrics.sidebarJSONFile#’ ) /><!— if this is valid JSON then let’s use it. —><cfif isJSON( sidebarJSON )><cfset sidebarStruct = deserializeJSON( sidebarJSON ) /><!— Display the sidebar contents —><cfloop collection=”#sidebarStruct#” item=”sidebarEntry”><span class=”list-group-item list-group-item-action flex-column align-items-start”><p><b>#sidebarEntry#</b></p><p class=”mb-1″>#sidebarStruct[ sidebarEntry ]#</p></span></cfloop></cfif></cfif>
You must be logged in to post a comment.