Skip to content

Instantly share code, notes, and snippets.

@mr-fan
Created June 22, 2014 09:45
Show Gist options
  • Save mr-fan/33f9b8690d132beec59f to your computer and use it in GitHub Desktop.
Save mr-fan/33f9b8690d132beec59f to your computer and use it in GitHub Desktop.
Individual CSS and JS for Processwire trick from Ryan
<head>
<!-- all your typical <head> stuff -->
<?php
$file = "styles/$page->template.css";
if(is_file($config->paths->templates . $file)) {
echo "<link rel='stylesheet' type='text/css' href='{$config->urls->templates}$file' />";
}
$file = "scripts/$page->template.js";
if(is_file($config->paths->templates . $file)) {
echo "<script src='{$config->urls->templates}$file'></script>";
}
?>
</head>
@mr-fan
Copy link
Author

mr-fan commented Jun 22, 2014

Using this method, if you have a template named 'product', then it could have dedicated CSS and JS files in /site/templates/styles/product.css and /site/templates/scripts/product.js, when you need it. The nice thing about this is that it's just a system rather than hard coded file. If you determine you need something unique for the CSS (or JS) on pages using some template, the you can just create the CSS (or JS) file and have it start working automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment