All,
More of a design question for an intermediate n00b like me. I am wondering about my increasing use of JS libraries throughout my site. Some provide very specific functionality - such as PDF.js to display pdf's in a browser. I want to use common templates for my various site pages and keep the count of templates as low as possible. Currently my "logged in" template has all the JS includes at the bottom. As you can assume, every page using that template loads all the JS libs whether they are needed or not.
I was trying to think of a way that i could set a PHP variable on the inner PHP portion of the rendered page, my logic for page rendering is as follows
$f3->route('GET /',
function($f3)
{
$f3->set('name','Login');
$f3->set('content','login/index.php'); //page logic
echo View::instance()->render('login/template.php'); //template
}
);
So i'm thinking of a way to essentially place a variable in login/index.php that the template can read the right libraries in
I do this for page specific self-coded javascript requirements
$f3->route('GET|POST /dashboard/@idx',
function($f3)
{
$f3->set('js','/'.$f3->get("PARAMS.idx").'.js'); //load any per-page custom js code here
$f3->set('pagetitle',ucfirst($f3->get('PARAMS.idx')));
$f3->set('content','home/'.$f3->get("PARAMS.idx").'.php');
echo View::instance()->render('home/template.php');
}
);
What do people do to dynamically load the JS libraries they need for a page when using templated HTML with PHP includes?