I have a template file that contains standard text, that I would like users the ability to "customize" it using settings defined elsewhere in JSON files. A typical settings file looks something like:
user.json
{
"name": {
"first": "John",
"last": "Doe"
},
"address": {
"addr1": "123 South St",
"city": "Citiville",
"geo": {
"lat": "123.123123",
"long": "80.123123"
}
}
} The way the templating works is that custom variables can be added by using a format that we define and is inserted into the file by the use of pre-defined buttons adding, for example the LAT and LONG:
- {{
- NameOfJsonFileInUpperCaseWithoutExtension
- _
- ListOfArrayElementsInOrderDenotedByHyphens
- }}
So, after placing the cursor in the template file where you want to add your LATITUDE, pressing the respective button on the toolbar adds something like the following in the template file
You can find us using {{USER_ADDRESS-GEO-LAT}}
would get parsed as required to read user.json (from a pre-defined folder) into an array and then using the ['address']['geo']['lat'] elements of that array to get the actual data being requested and so when the template file is actually presented to the user, it reads:
You can find us using 123.123123
I've gotten so far as to get the elements as a string, and the file contents json_decoded into an array but I can't seem to figure out how to denote an array's elements with a variable.
$elements is currently (and literally, including quotes and square brackets)
['address']['geo']['lat']
and $contentArray is simply the file contents as an array
json_decode(file_get_contents('user.json', true));
But, I can't work out how to get the actual data - I thought I'd have to use those lovely curly braces but I can't seem to get it...
- $contentArray"{$elements}" is the "closest" but I get Array['address']['geo']['lat']
- $contentArray[$elements]
- ${"contentArray . $elements"}
I'm beginning to think this isn't possible, but thought I'd ask you fine chaps and chappesses out in SO land if I'm barking up completed the wrong tree...?