redux-framework icon indicating copy to clipboard operation
redux-framework copied to clipboard

Dynamic CSS

Open miishu opened this issue 12 years ago • 9 comments

Hi guys,

I am using : Redux Framework v3.1.8 I embedded it into my theme folder.

Last time I was in a problem to generate dynamic css with redux which I solved later on... Thanks to Redux, It's really awesome.... Dovy and Kevin helped me to find my answers.

Now I am in an another problem... This is my code of a specific field : array( 'id' => 'primary-color', 'type' => 'color', 'output' => array('.site-title'), 'title' => __('Primary Color', 'redux-framework-demo'), 'subtitle' => __('Pick a Primary color for the theme (default: #fff).', 'redux-framework-demo'), 'compiler' => array('.menu ul.main-nav li a:hover','#navigation .menu ul > li.current > a','.column i','#feature .wrapper h2','#feature .ft-two','#feature .ft-one','.footer-wrap p span a','.slider-caption h2 span'), 'default' => '#FFFFFF', 'validate' => 'color', ), Here I used "color" as the css attribute... Its working really fine..

Now I want to use this field value to another css selector. Suppose for "background-color" for other group of selectors...

To be specific the user chosen value from this field will be used as another css property in another section. Thanks in advance....

miishu avatar Mar 10 '14 09:03 miishu

Two different selectors from the same field? I don't think it's possible. You can change the selector via mode ('mode' => 'background-color'), but you wouldn't be able to use both. There would be no way to assign which mode to which class. The only workaround I can think of is to manipulate the output in the compiler_action function.

kprovance avatar Mar 10 '14 15:03 kprovance

Yea, use the compiler to do this when they change a compiler field. We won't link fields in that way. That kind of logic is up to the developer. ;)

dovy avatar Mar 10 '14 15:03 dovy

Hi, I'm having hard time to use create css compiler. I have follow step by step on this page http://docs.reduxframework.com/redux-framework/advanced/updating-a-css-file-dynamically/ but I didn't get anything work. There is no css file create or write. What should I do?

kamalcha avatar Mar 16 '14 05:03 kamalcha

did you set the field you want to compile something like this?

'compiler' => array('body, #header, #footer'),

SilverKenn avatar Mar 16 '14 05:03 SilverKenn

Yes already did it, follow exactly like on the documentation page. Should I create a style.css file on the same folder as config file? or it will create automatically?

kamalcha avatar Mar 16 '14 05:03 kamalcha

Try a print_r of the $css variable passed like in the sample-config. There's actually a full working example there.

dovy avatar Mar 16 '14 05:03 dovy

verify if the compiler run

add something on the compiler function like

function compiler_action($options, $css) {
            add_action('admin_notices', 'compiler_notification');
            function compiler_notification() {
                echo '<div id="info-notice_success" class="redux-success  redux-notice-field redux-field-info"><p class="redux-info-icon"><i class="el-icon-info-sign icon-large"></i></p><p class="redux-info-desc"><b>Compiler Run</b><br>You have successfully Updated the auto-generated files!</p></div>';
            }
            print_r($css); // Compiler selector CSS values  compiler => array( CSS SELECTORS )


              // Demo of how to use the dynamic CSS and write your own static CSS file
              $content = '/*! ** This file is auto-generated from Theme Options, You should never edit this file directly! ***/'."\n". $css ;
              $filename = CMK_DIR . '/output' . '.css';
              global $wp_filesystem;
              if( empty( $wp_filesystem ) ) {
              require_once( ABSPATH .'/wp-admin/includes/file.php' );
              WP_Filesystem();
              }

              if( $wp_filesystem ) {
              $wp_filesystem->put_contents(
              $filename,
              $content,
              FS_CHMOD_FILE // predefined mode settings for WP files
              );
              }

        }

and make sure this the directory exist

$filename = CMK_DIR . '/output' . '.css';

you don't have to create any stylsheet

SilverKenn avatar Mar 16 '14 05:03 SilverKenn

If you created your config file with the generator, you don't have the initSettings() function spoken of in the documentation. Instead, you have loadConfig()

Second, do not put the line add_filter('redux/options/'.$this->args['opt_name'].'/compiler', array( $this, 'compiler_actions' ), 10, 3); at the beginning of the function. At that point, $this->args['opt_name'] is undefined so your compiler_action will not run.

Thirdly, if you are putting that code in loadConfig(), then the array $args is defined in that same function. $this->args would refer to an array defined in the class. To pick the correct value, use $args['opt_name'] So, in loadConfig(), add add_filter('redux/options/'.$args['opt_name'].'/compiler', array( $this, 'compiler_action' ), 10, 3); just before $ReduxFramework = new ReduxFramework($sections, $args);

kakoma avatar Jun 21 '14 17:06 kakoma

Hi.

  1. Please do not piggyback old tickets. Create your own.
  2. Make sure you include the necessary info (https://github.com/ReduxFramework/redux-framework/blob/master/CONTRIBUTING.md)
  3. When you create the new ticket, you'll have to tell me where you are seeing 'loadConfig', because I cannot find it anywhere.

kprovance avatar Jun 21 '14 19:06 kprovance