Forums / Templates, Stylesheets, Page Layout / Children support for category-specific stylesheet overrides

Children support for category-specific stylesheet overrides

Views: 661

Results 1 to 6 of 6
13 Nov 2012, 5:47 PM
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,114
Plugin Contributions:
56

Children support for category-specific stylesheet overrides

This new feature in v1.5.1 sounds like a great idea, but I'm not sure how practical it is. I composed a small test for a stock Zen Cart v1.5.1 install, creating three files in /includes/templates/classic/css:

c_54_children.css: .centerColumn { color: green; } ... New v1.2
c_54_55.css: .centerColumn { color: blue; } ... New v1.2 ... Discount Qty
p_127.css: .centerColumn { color: red; } ... New v1.2 ... Discount Qty ... Normal Product

My expectation and the actual text color for the various pages are as follows:

main_page=index&cPath=54, expected=black, actual=green
main_page=index&cPath=54_56, expected=green, actual=green
main_page=index&cPath=54_55, expected=blue, actual=green
main_page=product_info&cPath=54_55&products_id=127, expected=red, actual=green

My expectation for cPath=54 being black is that it's not a child of itself so the _children file shouldn't have been loaded. I expected that the c_54_55.css file would override the c_54_children.css in standard CSS fashion; ditto with the p_127.css as it was more specific.

Am I simply harboring false expectations or is this a problem with the way the _children.css files are loaded?

14 Nov 2012, 4:32 AM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Children support for category-specific stylesheet overrides

This was discussed a while back: CSSreadme clarifications
The issue is partly terminology (_children implies excluding the referenced category and can lead to confusion) and partly function (the broad _children files load after specific category files, not before as they ought to).

14 Nov 2012, 12:39 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,114
Plugin Contributions:
56

Re: Children support for category-specific stylesheet overrides

Thanks, Glenn. I was pretty sure that I'd seen the discussion elsewhere but couldn't find it searching for children. Looking at the code in html_header.php, it's obvious that the c_xx_children.css files are currently loaded after **all **other stylesheets for the page except for the print*.css files.

14 Nov 2012, 7:37 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,114
Plugin Contributions:
56

Re: Children support for category-specific stylesheet overrides

I've taken the liberty of recoding the portion of the CSS-loading section of /includes/templates/template_default/common/html_header.php to adhere to the CSS_read_me.txt file updates that Glenn provided in his referenced suggestion. A more-specific c_xx_yy.css file is loaded after a c_xx_yy_children.css file and a p_xxx.css file is loaded after that ...

/**
 * load stylesheets on a per-page/per-language/per-product/per-manufacturer/per-category basis. Concept by Juxi Zoza.
 */
  $manufacturers_id = (isset($_GET['manufacturers_id'])) ? $_GET['manufacturers_id'] : '';
  $tmp_products_id = (isset($_GET['products_id'])) ? (int)$_GET['products_id'] : '';
  $tmp_pagename = ($this_is_home_page) ? 'index_home' : $current_page_base;

  if ($current_page_base == 'page' && isset($ezpage_id)) $tmp_pagename = $current_page_base . (int)$ezpage_id;
  $sheets_array = array('/' . $_SESSION['language'] . '_stylesheet',
                        '/' . $tmp_pagename,
                        '/' . $_SESSION['language'] . '_' . $tmp_pagename
                       );

  $tmp_cats = explode('_', $cPath);
  $value = '';
  foreach($tmp_cats as $val) {
    $value .= $val;
    $sheets_array[] =   '/c_' . $value . '_children';
    $sheets_array[] =   '/' . $_SESSION['language'] . '_c_' . $value . '_children';
    $value .= '_';
  }
  
  $sheets_array2 = array('/c_' . $cPath,
                         '/' . $_SESSION['language'] . '_c_' . $cPath,
                         '/m_' . $manufacturers_id,
                         '/' . $_SESSION['language'] . '_m_' . (int)$manufacturers_id,
                         '/p_' . $tmp_products_id,
                         '/' . $_SESSION['language'] . '_p_' . $tmp_products_id
                        );
                        
  $sheets_array = array_merge($sheets_array, $sheets_array2);
  
  while(list ($key, $value) = each($sheets_array)) {
    //echo "<!--looking for: $value-->\n";
    $perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . $value . '.css';
    if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
  }
14 Nov 2012, 9:28 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Children support for category-specific stylesheet overrides

Thanks! I was thinking about doing that... I have an Improved Stylesheet Calls mod in Plugins that does some of the things the new html_header does, and a couple that it still doesn't do (like ez-page chapter stylesheets), as well as efficiency improvements. I might take a stab at integrating these in the spirit of offering code examples to work from.

15 Nov 2012, 1:40 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,114
Plugin Contributions:
56

Re: Children support for category-specific stylesheet overrides

Sounds good, Glenn. I look forward to seeing your updates.