I have searched around and tried a few of my own ideas and had no luck. Is there a way either with php, jquery or ajax to grab the variable and use it in the head tags?
Thanks guys.
Here is how I would do it..
I would write a controller file and put the head content and body content into arrays, then I would search for naming conventions or functions in the body.. then add the function or variable to the head array.
Finally, build the template. arrays:
$head = array();
$body = array();
$head[] = '<title>My Title</title>';
$head[] = '<script>some script here</script>';
$body[] = '<h3>Hello World</h3>';
$body[] = myfunction();
Now you can search the $body array with a pregmatch looking for myfunction or if you prefix the variables with $head_myvariable you can search for head with pregmatch.. if it exists.. Simply add the variable to your head array:
$head[] = $mybodyvariable;
Now you can publish everything:
foreach($head as $h) {
echo $h;
}
foreach($body as $b) {
echo $b;
}
You will need to do a little research on preg_match as the regex is different for everytype of search.. so google this php: preg_match
Good luck, hope that helps.
精彩评论