I have a dynamic web-app using MySQL, PHP, jQuery, JavaScript and Twitter Bootstrap.
I've created a few color theme options for the users, but I'd like to offer them the ability to setup their own color schemes. I'm not entirely sure of the best way to go about this.
I'm guessing I would allow the users to save the key colors into a database table and use a generic CSS file where I can replace the values. But I'm not sure how to do the last part of that.
How would I write into the CSS file replacing "tokens" or variables, before it's loaded by the website? Or should I use jQuery to replace the CSS at runtime?
Thanks
Related
DNN 9.3.2 / 2sxc 10.25.2
I have a DNN theme that I use for a certain type of subportal - I will have 8 subportals ultimately. Each subportal has the same layout, but they will have different colours in their respective theme. So I will have to create a stylesheet with the CSS rules and the colours for each theme. I know there is a couple of relatively simple ways I can do this:
Modifying the portal.css of each portal to override the theme or (simple but might be hard to maintain updates)
Building a custom theme for each portal (overkill)
Using SCSS to create a template with 8 different variable files (works fine but doesn't allow modifications by the Content Editors)
So, I'm curious if there's a more clever way through 2sxc that makes it easy for not only me to maintain, but also my portal's Content Editors.
I want to create 2sxc Content module with a few different fields for colour pickers that will allow me (and my content editors) to simply open up the 2sxc edit modal (on the homepage), fill out all the colour fields, and then a razor template will output the CSS template with the colours to override the theme styles on the DNN skin. I know I can do this with inline CSS but that would mean the module would have to appear on every page, and I'd also prefer to avoid inline CSS.
So my idea is that it would work like this:
Have a 2sxc Content module on a single page on each portal
Edit modal > the fields would be something like: primary colour (rgba), secondary colour (rgba), grey colour (rgba), etc
Once save is clicked, the template modifies a portal-level theme.css file which is loaded by the skin
Any changes to the module would result in a rewrite of the CSS file.
I could update the c# razor template to add, remove, or modify rules or transform the values of the input.
Is this possible or is it too complicated? Is there a better way of going about this?
So I've been away for a long time, I hope my answer will still help...
We have a very simple solution :). If you check out bootstrap instant template you'll see that we add various classes to the <body> tag.
https://github.com/2sic/dnn-theme-bootstrap4-instant/blob/master/controls/body-css-classes.ascx#L86-L91
That way we can just use normal CSS of the theme with rules based on portal-27 etc. to vary by portal.
I have an application that has a page where the user can choose two colors, color-primary and color-secondary, and press a button to apply the colors.
Once the button is pressed I want this page to update the values of SASS/SCSS variables and compile a new style sheet.
Any ideas on how to achieve this?
I would prefer to use inline styles on the html, as this will override any css files. You could store the values in a cookie so that you can retrieve them later on. When you check for the cookie and find it you can set it again, that way it shouldn't expire. It should be fine for storing styles. You could use https://plugins.jquery.com/cookie/ to store and retrieve the cookies.
If it this was for some sort of backend cms and you need the CSS files to be stored permanently you could always just write the changes straight to a custom CSS file and link to that, this would be better than compiling SASS/SCSS on a server. I would use fwrite() in PHP for something like that.
http://php.net/manual/en/function.fwrite.php
If you really need to compile on your server though, first you'll need to install SASS/SCSS on to your server and then you could run it from exec() in PHP, or something similar in another language in the same way that you would from the command line.
http://php.net/manual/en/function.exec.php
Meteor template are great for different data in the same style.
What if thousands of pages have to have their own style? I assume this will require all pages to have their own template.
For example, how could I store and fetch javascript animations?
Is there any easy way to do this or do they have to be individual template files?
I've been able to customize the style of pages dynamically (using JS) by using the package ccorcos:reactive-css. It lets you create CSS style sheets using JavaScript and using that you can adjust it depending on what page is being shown, or what data is coming from the DB.
You could even generate JS animations on the fly.
I'm creating a small WordPress theme, which has a separate control panel. This panel has a lot of color and font changes. I had no problem in saving all the data into mysql, but I can't figure out the best way to apply these changes to the design.
What I want to ask, is what is the best, most efficient and popular way to apply color and font settings?
Should I apply these changes with style="" while generating the design? Should I edit it with JavaScript? Include it in headers <style>, or maybe even edit the .css file?
The best way would be to make the changes directly to the css file. For this you would need to parse the css content. Grab a specific selector content and change it's properties.
An easy way is to output the custom properties in the page header (after the style.css in order to overwrite the default properties) or to put them in a separate css file.
Also, it my be helpful an existing Wordepress theme generator, like http://www.lubith.com
I have built a basic theme for my Flex app. I would like to add support for additional predefined themes. By default, app has a theme and I would like it to change when user selects a theme from dropdown list. This can be done by loading a swf file using styleManager. However, all the skins have colors hard-coded in them. So, in order to achieve this I would have to duplicate skins and change value of the colors.
Is there a better way of doing this? Can I just have a skin that will change color values dynamically based on user selection?
The best way is to move all hard coded colors from skin to the css.
You will have to update your custom skins to take advantage of that.
so if you have a <SolidStoke color="0xff0000" />
you need to replace it by <SolidStroke color="{getStyle('yourCssPropertyName')} />
Another way to do it is to write your skins so they have references to their host components (see [1]). Then you extend the current host components so that they have properties for each color you want to specify (e.g. instead of using , you'd use with borderColor and fillColor as new properties).
Honestly, though, Florian's answer is probably the better way to go.
[1] - http://www.adobe.com/devnet/flex/quickstarts/skinning_components.html#host