css() attributes

edited September 2011 in Feature Requests
Hi all.

Is it possible to set css link attributes such as 'media' using css() helper?

Thanks

Comments

  • edited 8:47AM
    Yes. The third attribute is an associative array that contains additional parameters you can pass to the function including "attrs"
    http://www.getfuelcms.com/user_guide/libraries/asset
  • edited 8:47AM
    Thanks, all good.
  • edited 8:47AM
    Is there a way of setting css link attributes when using page variables (i.e. in the global variables file)?

    My problem: I need to set different print only css files for different pages.

    Thanks.
  • edited 8:47AM
    There are a couple ways you can do that. First, it sounds like you'll need a variable that you can use to manipulate the media type for the CSS file you want to include-- let's call it $css_type. To specify that variable, you can use a variables file as shown below (example is using a views/_variables/company.php variables file):

    // would apply to all pages within a particular URI segment of "company" $vars['css_type'] = 'print'; // would apply to only the company/about page $pages['company/about'] = array('css_type' => 'print'); More on specifying variables using the "opt-in controller" method can be found here: http://www.getfuelcms.com/user_guide/general/opt-in-controllers

    Another method for creating that variable, and one that works well if you are using static view files is to use the fuel_set_var() function at the the top of your view file:

    // company/about view file fuel_set_var('css_type', 'print');<code> Then in your header you can add something like this: <code><?=css($css, NULL, array('attrs' => 'media="'.$css_type.'"')?>
    You may need to make a check for the existence of the $css_type or you can simply add it as an empty value in your global.php variables file:
    $vars['css_type'] = '';
Sign In or Register to comment.