Hi all,
Is there a way of using a css template, similar to the Requirements::javascriptTemplate method?
I have checked the API documentation, and I cant see a cssTemplate method, or anything similar.
Any Ideas?
Mo
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hi all,
Is there a way of using a css template, similar to the Requirements::javascriptTemplate method?
I have checked the API documentation, and I cant see a cssTemplate method, or anything similar.
Any Ideas?
Mo
Do you need to know about importing a CSS file to the webpage?
if that is the question you can do it with Requirements::css('filename');
No, I was looking at replacing a variable in my css with something generated by the CMS.
In this case, the background image for the page is chosen in the cms, and then needs to be added as a background image to the css for the page.
There are also options for adding padding to the page and positioning the image, so that its alignment can be fine tuned.
Cheers,
Mo
Hi Mo
I usually do such things like this:
Create the stylesheet the usual way, maybe even with default values for the customizable Parameters.
In the template, I add a custom <style> block where I add the custom style values. If you got a BackgroundColor member for your Page class, you could add the following to your Page template:
<style type="text/css">
body { background-color:$BackgroundColor; }
</style>
Or, for increased flexibility, use the Requirements::customCSS method which does basically the same.
I think this procedure is way faster in terms of processing time and page load (since the base css file remains static and can be cached).
This site: http://jugendfachstelle.ch/ is a good real-life example for this. The Administrators of the site can freely choose the background color and the color of the stickies.
I am using Requirements::customCSS currently. which works fine. But I like my code to be as separate as possible, so that my CSS, JavaScript and PHP can be in separate places.
Probably a bit O.C.D, but that way I don't have to start searching through PHP classes looking for CSS that is overwriting something else :).
Mo
You've got a point, that's why I'm putting the code directly into my templates instead of using Requirements::customCSS. Not optimal too, but the template belongs to the view, and so does the CSS.
If you would use something like a "CSS Template" as described in your first post, you would still mix CSS with PHP, just in a more subtle way. In that case, figuring out where CSS definitions come from will be even harder than the other way round.
That makes sense, I guess personally I have a naming convention that any css/js files specific to a class contain the class name in their filename (or as there filename). So I can fairly easily pick out class specific files.
That process does end up with a lot of small files, if you aren't careful though! :S
I think I will start putting CSS like this into my templates though, I think that follows the whole MVC thing a bit more closely.