I need to change values in a stylesheet from an admin panel using php. I know I can do this inserting the values to my MySql database but isn't there a better way?
So far I have converted my style.css to style.php and it looks like this:
<?php
header("Content-type: text/css");
$pageBG = '#ff0';
?>
What I want to do is to change the hex value (#ff0) from my admin panel with a color picker.
You are asking too much.
A color picker needs at least javascript
An admin control panel needs at least a database + an auth plataform
You should open another question with more specific stuff.
If you want the easiest way you can just edit your style.css file and make your changes by hand.
If you want to use color picker it's a frontend issue not related to having it configurable at all. If you want to make admin panel's or site's look customizable, there's no other way than storing some settings in database. You may utilize INI files, but's that only other container. One tip: Generate CSS file and don't regenerate it until you tell you script to. If you save new settings - regenerate it, other way use the already existent one.
You cannot change css, though you can dynamically generate it.
Supposing you are using apache you can have .css files go through php before being served. thus you could have something like
.dynamicColor
{
color: <?= $color ?>;
} /* $color must be exctracted from mysql */
more general solution would be to create a php script createCSS, which would load variables from mysql and include prebuilt css script (like in previous example) and set content-type header to text/css
Related
We recently changed our front-end and start using Metronic responsive theme.
I have a left menu like:
Now since this is responsive if you click top left of the menu it resizes perfectly like this:
The problem is even if you resized it( for ex: small), when you click a link (or when page is refreshed), regardless of the size it automatically displays the big menu.
if (resize) { use -> page-header-fixed page-sidebar-closed }
else { use ->page-header-fixed }
I know it must be something like that but how to implement this in php?
EDIT: I have an body class inside index.php like :
</head>
<body class="page-header-fixed">
<?include "left.php"?>
left.php is the page that has the left menu.
body class is the css class that I need to check
Do this setting must be stored on your database? If not, why not use localStorage and manage it with - and only - JavaScript?
I don't know your menu code, but if you can watch it open and close event, you can just use:
window.localStorage.setItem("menu", 1); // 1: open - 2: closed
Then on page load read it:
window.localStorage.getItem("menu");
No need to set ajax requests to the server nor cookies and that kind of crap.
You should perhaps add another js condition to test minimum offsetWidth before choosing css classes.
Otherwise, I wonder if you added responsive CSS #media min-width on both classes, page-header-fixed page-sidebar-closed.
If your JS doesn't overide these classes, CSS should do the job to keep your menu on "small size" look.
In any case you need a variable to store the state of your menu i.e., big or small.
If you want to do it with PHP you can use session variables and use ajax to update that value when the menu is resized.
OR you can set a cookie with Javascript for the same purpose. I would go for this option.
Either way you will need to check the value of the cookie / session var and change the class of your menu depending on it.
---EDIT---
Or as our respectful fellow programmer says, it might be a good idea to use localStorage since the information doesn't need to be sent to the server.
In the site i'm developing i would like to have users set their own custom "css" on their profile pages.
For example, i give users the ability to select a background color for <body> with a js color picker.
Then with php i create a 'css-ready' string and save it on db.
What i am asking is: how i can make this css apply everytime a user enter another user profile?
Probably will be there a lot of thing a user can customize, so there will be a big css string and i need something that will be cross browser and if possible that work also without javascript..
Thank you.
You could try a php file with header for content-type text/css which echos the CSS according to one fetched from Database, you could add default CSS to your website and just create a last in list of link tags the path to that php files, this way you have a default CSS to fall back and customized CSS to be applied on top of default if defined any..
This can be done with Handler in asp.net. I am sure there will be similar solution available in PHP also. First you need to save the style properties in a database for each user. Make sure that the syntax of the styles (selector name, curly brackets, semi-colons, etc.) are in order. You can get the user information from session object or pass the variable with query string to the handler.
The response received from the handler can directly be put between tags as content type - text/css like this:
And with this you should be ready to go!
However, it will lead to performance losses as everytime the page loads, the entire file will be loaded (in normal css file, it is loaded only once). It will be a better idea to save only those items in database which you really want your user to customise. You may cascade it with your parent css file for better performance.
you can use this is user-profile.tpl.php
<?php
if(isset($account->user_css)){
?>
<style>
<?php echo $account->user_css; ?>
</style>
<?php
}
?>
I'm quite new to Drupal and want do some editing of the header. I want a custom toolbar to appear on every page. I've already created that toolbar in a file called toolbar.php. It has a layer which is fixed and will appear on top of every page.
How do I include the toolbar.php in the header template of drupal?
The toolbar refers to $user which is a global Drupal variable and I want to test toolbar.php before publishing it to the site. Is there anyway I can do that?
Regards,
Dasith
Of the two methods above the first is easier if you understand the basic idea of html and CMS templates, the second will be easier if you are a programmer.
First thing to check is that you really need to do this! Can't you restyle one of the existing menus (Primary or secondary) to do this - will make your life (and anyone who works on the site in the future) a lot easier.
The other thing you can do is look into adding an output region, basically something where you put the php into a drupal friendly format and then effectively do a 'drupal print'. This is how the toolbar, search box etc are done. You still need to alter the templates as above.
Yes for sure. If you want to have the html produced by your function/file appear on every page of the site then you will need to over-ride the page.tpl.php file in the theme you are using and essentually add the html to that file.
To gain access to the $user variable, just declare it in your script.
global $user;
open page.tpl.php file in a code editor and save as page-front.tpl.php (with two dashes if you are using Drupal 7.. one dash with Drupal 6) and upload it to your theme's directory. Clear your cache by going to configuration->Performance->Clear All Cache. Then referesh the page. Now your homepage is using page-front.tpl.php as it's template file. Every page will need its own template file. The page machine name comes after the hyphen so the user page template uses page-user.tpl.php. You can edit it as you want. The proper way to really do this is to use hook_theme() to pass variables to the template file. One variable could be the html which creates your custom header.
See also http://drupal.org/node/457740 Beginners Guide to over riding theme output
I have a website running on osCmax setup by a developer a while back and now I want to restyle some of the pages myself from the markup and CSS only.
I'm familiar with HTML/CSS and some jQuery to an extent but I have never touched any PHP. This is my first time really getting into any of the osCmax pages, site, etc., myself so I am little confused on what it really is or does.
If I want to edit any of the HTML/CSS myself for styling pages will I have to download and login to the osCmax admin panel to get to any of the files?
Or can I just go directly through my server to grab the appropriate HTML and CSS files? Wouldn't all the necessary files from the download be on my server already or is this something that I have to download to use?
If all you want to do is restyle the pages, then just modify the css. You shouldn't need to modify the PHP (unless parts of your HTML are created with out a class or id).
oscmax has a seperate folder for its template. all you have to do is editing the .css file. but sometimes you need to design the template from scrath and since the OSCMAX is outdated you must edit all the pages with .tmpl prefix.
How can I give the user the ability to change the style of a webpage, of course I have to make several CSS files , but how can I make the code that permits the change upon the user's choice
We're all pretty unlikely to give an answer as thorough as A List Apart's.
They even provided some freely-usable code for you.
You would basically have css classes for all the major components of the page such as header, content, footer, nav_menu items, heading, etc. Everything that you want the user to be able to customize you would create a css class/ID for it.
Then you would show all these classes to the user and let him either type in the CSS code manually, or show him dropdown boxes with all the possible colors, for example, or other settings.
When the user changes an option, you could use javascript to change that property of the css ID/class he selected. E.g if he changes the background color of the header from black to blue, you could do this:
document.getElementById("header").style.background-color="#ABCDEF";
(Jquery might have an easier way of doing this)
At the end of the page you could have a submit button which would POST all the css settings to a php script, which would write these settings to the database. Then you would do a query like:
SELECT css_id,css_class,css_code FROM css_styles WHERE user_id='$user_id';
This would return all the css code, and then you would put this in the <head> command instead of an external css file.