Jump to content

Modules CSS listed in $config->styles (frontend)


formmailer
 Share

Recommended Posts

Hi!

I'd like to make it a little bit easier to add custom stylesheets and scripts that are only required for specific templates.

All my template call main.php, which contains 99% of the markup.

In my main.php I added the following code:

<?
/*Load required scripts and style sheets*/
$config->scripts->prepend("https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
$config->scripts->add($config->urls->templates . "scripts/all-js-min.js");
$config->styles->prepend($config->urls->templates . "styles/main-min.css");
$config->styles->add($config->urls->templates . "styles/jquery.fancybox-min.css");
?>
<?
foreach($config->scripts->unique() as $file) echo "\n\t<script type='text/javascript' src='$file'></script>";
foreach($config->styles->unique() as $file) echo "\n\t<link type='text/css' href='$file' rel='stylesheet' />";
?>

Everything is working, but for some reason the ProcessRedirects.css of Apeisa's great ProcessRedirects module gets also loaded. This isn't a big issue, but I don't understand why this one is listed, while CSS files of other modules are not. Can someone explain this?

/Jasper

Link to comment
Share on other sites

Jasper - that is probably because it is kind of special case: process module that is also autoload module (because it needs to sniff the 404 visits).

I will fix this soon, thanks for letting me know.

  • Like 1
Link to comment
Share on other sites

Also wanted to add that using $config->styles or $config->scripts on your own site is totally optional, unless you are using some module that requires them (none of the core modules do). They were designed for use by the admin template. I rarely use them myself, but if they suit your needs on the front-end, then no harm in using them.

  • Like 1
Link to comment
Share on other sites

I am using:

$config->styles->removeAll();

$config->scripts->removeAll();

on each template, before anything similar to yours snippet above, formmailer!

Thanks for the tip!

Also wanted to add that using $config->styles or $config->scripts on your own site is totally optional, unless you are using some module that requires them (none of the core modules do). They were designed for use by the admin template. I rarely use them myself, but if they suit your needs on the front-end, then no harm in using them.

The reason I started using them is that I have a main CSS, a main JS and a main template, but there are a few templates (they still use the main template) that need a little bit more CSS and javascript and I want to avoid loading unnessecary code on the main part of the site.

Using $config->styles and $config->scripts is an easy way to add the scripts to the head section of the template.

/Jasper

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...