I have some encoded JSON data stored in my database, like the following:
{".main-header":"{\"color\":\"rgb(5, 213, 255)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"NeutraText-Book\",\"font-size\":\"35px\"}",".main-header-free":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"NeutraText-Book\",\"font-size\":\"22px\"}",".sub-header-lunch-price":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"NeutraText-Book\",\"font-size\":\"22px\"}",".sub-header-week":"{\"color\":\"rgb(62, 214, 24)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"NeutraText-Book\",\"font-size\":\"22px\"}",".sub-header-week-week":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"NeutraText-Book\",\"font-size\":\"22px\"}",".day-name":"{\"color\":\"rgb(237, 129, 5)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"NeutraText-Book\",\"font-size\":\"22px\"}",".lunchtext":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"Baskerville\",\"font-size\":\"13px\"}",".puffheading":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"NeutraText-Book\",\"font-size\":\"22px\"}",".pufftext":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"Baskerville\",\"font-size\":\"13px\"}",".re_name":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"'Times New Roman'\",\"font-size\":\"13px\"}",".re_address":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"'Times New Roman'\",\"font-size\":\"13px\"}",".re_phone":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"'Times New Roman'\",\"font-size\":\"13px\"}",".re_webpage":"{\"color\":\"rgb(0, 0, 0)\",\"background-color\":\"rgba(0, 0, 0, 0)\",\"font-family\":\"'Times New Roman'\",\"font-size\":\"13px\"}","html":"{\"background\":\"none\"}"}
This is how I would do it with jquery:
var currentStyle = {{ $theme->css}};
$.each(currentStyle, function( index, value ) {
$(index.toString()).css(jQuery.parseJSON(value)));
});
In my Controller, I render the view and then converts it to a PDF:
$view = View::make('pdf.template')
->with('css', $css);
$pdf = PDF::loadHTML($view);
return $pdf->stream();
This means that the view rendered will return the DOM in its initial state, I cannot use any JavaScript to apply the JSON CSS with say jquery, because of that.
So can I directly convert this JSON to CSS through PHP somehow?