Jump to content


Photo

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

$config-styles

  • Please log in to reply
4 replies to this topic

#1 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 263 posts
  • 46

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 18 April 2012 - 06:25 AM

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

#2 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,154 posts
  • 1705

  • LocationVihti, Finland

Posted 18 April 2012 - 07:32 AM

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.

#3 seddass

seddass

    Distinguished Member

  • Members
  • PipPipPip
  • 59 posts
  • 8

Posted 23 April 2012 - 11:08 AM

I am using:

$config->styles->removeAll();
$config->scripts->removeAll();
on each template, before anything similar to yours snippet above, formmailer!

#4 ryan

ryan

    Reiska

  • Administrators
  • 7,797 posts
  • 6572

  • LocationAtlanta, GA

Posted 23 April 2012 - 12:16 PM

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.

#5 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 263 posts
  • 46

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 23 April 2012 - 12:28 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users