I have been working with Upfront for the last couple of days and I am starting to get familiar with how it works. I am pretty sure its possible to make page templates from Json objects but I am missing a piece in the puzzle.
Let me explain what I think is going on with Upfront incase I have made any wrong assumptions.
This is my understanding of the workflow:
1. User requests a page
2. Upfront checks the database based on template hierarchy to see if a Json object exists
2.1. If a Json object exists the upfront serializes this Json object to Upfront data model to build the page
2.2. If no Json object exists in database then Upfront serializes the array in the templates layout file
3. Upfront builds the page based on the serialized data model(s)
This is all pretty cool as it means I can easily override pages layout just by writing a Json object to the database.
However, it has a major drawback in that it only works for pages that already exist. If you want to save a layout so that a user can select it when creating a new page then you have to have a template file.
It seems to create template files you drop in a php file named
page_tpl-type.php to the child theme.
This file looks something like this:
the_post(); $layout = Upfront_Output::get_layout(array('specificity' => 'single-page-type')); get_header(); echo $layout->apply_layout(); get_footer();
So from the looks of it, all this is doing is initializing a model then making a call to apply_layout().
As the model can be initialized from Json as well as PHP then it is obviously possible for me to create a page in the Upfront GUI editor and save it. Then copy the Json from the database to a string input in the template file and initialize it from Json.
So I have started digging around and trying to piece together how it works but it would be super helpful if someone could just give me the line of code to create a layout from Json.
I've been looking at the to_json() and to_php() methods so it also looks possible to take a Json file, run it through this function to get the PHP array and then do a var_dump to get the array to paste into a template file (although not really necessary once I get it working from the Json object I think, although I guess it may improve performance?).
I am pretty sure anyone familiar with the codebase should know the method call and be able to save me a load of time piecing through everything.
Anyone able to help me out and save me digging through the code all day?