Insert EPiServer page properties into CSS-files with EPiCssModifier
Have you ever wanted to replace hard wired image urls in your css files with images selected from EPiServer? That is, without using inline css in your templates.
Usually, your css may look something like:
You want to let the editors pick the image for the logo, right?
If you’re using PageTypeBuilder – which you should – then it’s only a matter of adding a property attribute to your page type class. Like so:
The CssFragment attribute in the property declaration means that you want to replace /ui/gfx/logo.png in all css-files with whatever value LogoImage contains.
What happens when you render the page is that the css links are modified slightly. This is your original css link:
Instead, it will render:
Note the appended query string to the css link.
Then a http handler will catch the request to the css-file and do a simple search and replace based on the query string parameters. The result will be a css that looks like this:
1. EPiServer CMS 6
1. Unzip, compile and drop the EPiCssModifier.dll in your /bin
2. Add this to the Web.config:
3. Voila! You’ve got yourself an inline-css free road to happiness.
Download source and binaries for EPiCssModifier