Referencing multiple Kentico CSS definitions within one another

K Fisher asked on February 13, 2015 11:48

Hi, Im working on a website with alot of css which Id like to keep with Kentico but as separate css "files". I would like the main css "file"/object to pull in definitions from several other css "files/objects but I only know how to import css using format of:

@import url("base.css");

Ive noticed I cant find the css "files" defined within Kentico. Are the css definitions stored within the database? As I cant see them in the file system?

Appreciate any thoughts

Kate

Correct Answer

Stephen Rushing answered on March 9, 2015 22:50

In our case, we're using SASS, so embedded stylesheets need to use the actual stylesheet code, rather than the processed/cached version.

For that, I'm currently using this macro expression:

{% CMSContext.Current.GlobalObjects.CssStylesheets.MyOtherStylesheet.StylesheetDynamicCode #%}

Each @import url(...) creates a separate request, which may be excessive. If you want to reduce those requests, but don't need the dynamic code for a preprocessor, you can use the following to embed the processed/cached version:

{% CSS.Stylesheets["MyOtherStylesheet"] %}

The only disadvantage to these approaches that I've encountered is that you need to re-save the main stylesheet, after one of the embedded stylesheets is changed.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on February 13, 2015 14:48

Yes if you're using the Kentico UI to create your stylesheets they are stored in the database. You can import them using a URL like so:

/CMSPages/GetResource.ashx?stylesheetname=StyleSheetCodeName

The code name comes from the UI. Using the GetResource handler allows Kentico to minimize stylesheet as well.

0 votesVote for this answer Mark as a Correct answer

K Fisher answered on March 10, 2015 10:00

Many thanks for your feedback Stephen we need to use more than one sheet at times, this will definitely help.

Much appreciated

Kate

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.