Hello,
I'm working on my first project with PW. Working with PW is amazing so far. As I am coming over from the Joomla world I am used to adding scripts to individual pages with a Joomla built in method.
Searching for the PW way of doing this, I came along that post where I found this snippet of code:
$config->scripts->add($config->urls->templates . "scripts/lightbox.js");
Great, I thought. But using just that snippet wouldn't include the script. I had to add a second snippet
foreach($config->scripts as $url) echo "<script type='text/javascript' src='$url'></script>";
(which I also found in that other post) to actually load the script wherever I wanted in my template file.
Lets assume you are working with the default PW Profile on a fresh install and want to load the lightbox.js only on the homepage and the template file for your homepage is home.php.
Then you would include the first snippet in your home.php.
The second snippet goes either in your head.inc into the head section or in your foot.inc at the bottom (whereever you prefer to load your js).
This is a quite generic way to include scripts. If you wanted to have another script loaded only, lets say, on a contact page with template file contact.php the you just need to add a snippet, e.g.
$config->scripts->add($config->urls->templates . "scripts/contact.js");
to contact.php.
The second snippet
foreach($config->scripts as $url) echo "<script type='text/javascript' src='$url'></script>";
already sits in your head.inc or foot.inc where you put it before and it will take care of including also contact.js because of the foreach loop.
I guess that most of you already know this. But for a newbie like me I had to write this down to properly digest it and maybe it is helpful to someone else.
Cheers
gerhard