0

i develop a admin panel for manage colors in frontend. I don't want to add all color variables in theme files ( like header.phtml, footer.phtml, etc ) but i want to generate a file with all css class and color variables. Ex.

 <?php

$color = Mage::getStoreConfig('themeadmin/frontend/general_color'); 

echo '.top-header-container { background-color : #'.$color.'; } .menu { background-color : #'.$color.'; }'; 
?>

How i can do this without add this in theme file ? Can i generate a Css file ? what is the best way ? Thanks

Damac
  • 109
  • 1
  • 13
  • 1
    I'm voting to close this question as off-topic because it's not about Magento. Please consider posting the question on the more general oriented stackoverflow – Sander Mangel Mar 19 '16 at 10:44
  • Instead it is Magento, because what I have developed is an admin panel for my magento theme, for no other cms or php script – Damac Mar 19 '16 at 10:56
  • I'd suggest having all those CSS files in place in advance and based upon the user selection in admin, include the relative one in theme. – Prateek Mar 19 '16 at 11:53
  • @Prateek - Not often do I say this, but that is just crazy! ;) – proxiblue Mar 20 '16 at 23:43
  • Thanks Prateek, this is a simple way, but not totally customizable :) – Damac Mar 23 '16 at 12:26

1 Answers1

0

You can very easily simply call a .php file (or a controller action) as the actual stylesheet to be used.

ref: Include: css with php file extension?

So, considering that possibility you can do the following:

  1. Create a controller action in your module.
  2. Code for this action to simply output a valid formatted stylesheet
  3. Add that action to your layout, via xml, or programatically inject the sheet into the layout, potentially via an observer event/model/controller action

example:

Mage::app()->getLayout()->getBlock('head')->addCss(
      'dyncatprod/adminhtml.css'
);

Another possibility is to hook into the adminhtml save functionality (event should do) and generate one specific .css file form the admin options selected. The end result is one file, statically named, that you woudl then include normally. Make sure you provide a default base file for pre-saved instances.

This way would always ensure one file with the correct values, as a flat stylesheet.

Community
  • 1
  • 1
proxiblue
  • 433
  • 5
  • 19
  • Thanks proxiblue, can you give me a tutorial link or something esle for make this? because i'm new in magento and i develop the admin panel by tutorial. I try by inlcuding a css.php but the browser inspector give me an error :Failed to load resource: the server responded with a status of 403 (Forbidden). The permission of folder media/css/css.php is 775. But not work – Damac Mar 23 '16 at 13:29
  • Hi. Sorry, to busy to give code examples or google for you ;) - everything you need is in the answer. I'd go with option 2. So google on hoe to create a magento module, and then how to do observers for events, find teh right event, and write some code :) - Good luck – proxiblue Mar 23 '16 at 14:50
  • I am not sure on the forbidden issue. May be some security feature enabled in your webserver. Not done this for a while, so not sure if something has changes in regards being able to do it. but if you use option 2, this becomes a NOOP, you'd be able to output a fixed filename. Including that will be as normal. – proxiblue Mar 23 '16 at 14:54