Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

can i force themes css to load after extensions css?

ithcyithcy New
edited October 2006 in Vanilla 1.0 Help
since some extensions contain graphical or colored elements in css, it would be nice to be able to override all these bits in one place in a theme. i don't want to change the extensions css directly, obviously because people use different themes.

but it doesn't seem possible to do this without either:
- loading the extension css first and then redefining the css in the theme,
or else
- using !important for all these elements when they load first in the theme css.

#2 is not the nicest solution. is there another way? note that i'm no css genius so i've probably overlooked obvious things.

Comments

  • MarkMark Vanilla Staff
    I never even thought of that. I could change the AddStyleSheet method to have an index variable just like all of the controls have - so you can make your extension css come before or after the main css (or other extension css's). Would that solve your problem?
  • that would be awesome... i think it would solve my problem nicely.
  • MarkMark Vanilla Staff
    Okay, get the latest SVN. All css files (if no position variable is specified) will be added from 100 up. So if you wanted your css to come before, specity a position of 0-100, and if you want it to come after, specify a position like 200.
  • O_O

    that was fast. thanks, nav. excellent.

    so where does theme css come in? at 100? i'd just set all my extensions to 0-99?
  • NickENickE New
    edited February 2006
    Why not just print the stylesheet array in reverse order? As the theme stylesheet is added before any of the extension stylesheets, it seems to me all one would really have to do is start the loop at the end of the array instead of the beginning, and decrement towards 0.
  • because it's possible that some extensions need their css to override the theme css too.
  • MarkMark Vanilla Staff
    Regardless, the Head control was extended from Control, which already had a method for adding sortable collections. It was a very easy change and won't really affect performance.
  • so where does theme css come in? at 100? i'd just set all my extensions to 0-99?

    also, the new parameter would be added like so in the extension php?
    $Head->AddStyleSheet("./extensions/whatever/style.css",99);
  • MarkMark Vanilla Staff
    Oh, just take another look at the AddStyleSheet method of the Head control in library/Framework/Framework.Control.Head.php:

    function AddStyleSheet($StyleSheetLocation, $Media = '', $Position = '100') { if (!is_array($this->StyleSheets)) $this->StyleSheets = array(); $this->InsertItemAt($this->StyleSheets, array('Sheet' => $StyleSheetLocation, 'Media' => $Media), $Position); }

    So, if you don't care about the media specification, and you wanted to add your style before all of the other css sheets, do this:

    $Head->AddStyleSheet('./extensions/whatever/style.css', '', 0);
  • wubbles
  • edited October 2006
    I'm a new Vanilla user and I'm curious as to why you did not set the vanilla.css and vanilla.print css to a come after the default instead of at the default. It seems to me that this function is primarily used by extensions which have some basic styles they need added to the page. These extensions typically would prefer to be compatible with any theme and give it a chance to override the styles they are defining if the theme needs to. Besides making the extensions which did not implement this in the first place work correctly it would allow for extensions to be slightly easier to make in the future because you would not really have to worry about that last parameter. The exception would be when your extension was for use on a particular theme\style combination (which are the least useful type of extensions anyway). I have just installed a fresh copy of Vanilla and all of the extensions I have checked so far still load in the default slot which makes them load after the main CSS (which makes them difficult to theme) so even though this topic is old I think it still is relevant. Until then I guess I'm just going to go through all of my extensions and add ", null, 50" to all AddStyleSheet calls. I know at this point it may be difficult to make this sort of change because there may be extensions\themes out already which want to load after those two files and doing this may break some of those. But I would say that breaking a few things in development is worth fixing most of the old extensions (besides most things in development probably want to load first anyway so they won't be affected). BTW, Vanilla ROX
This discussion has been closed.