Stylesheet order - get_stylesheet()
Posted: Sat Mar 04, 2006 4:04 pm
QAers,
When associating multiple stylesheets with a template, I've been finding that the order in which they appear at runtime, in the generated stylesheet, appears to vary.
In a stock 0.11.2 installation, I added three stylesheets to a template, and...
1) the order in which they appear on the template-stylesheet association page after adding (e.g. admin/listcssassoc.php?type=template&id=19) is not always consistent. it's not appearing in the order added anyway. after deleting and re-adding multiple times, i've seen the order change around;
2) the order of presentation on that page does seem to reflect the actual record order in the underlying MySQL table (css_assoc);
3) the order of output, when the template's stylesheet is generated (from the {stylesheet} tag) seems to reflect the table order, but whatever that is i don't know, no keys on that table. it's possible that on a clean CMS install into a fresh db, that add order will be correct; however after records are deleted and added, order in a MySQL table may be unpredictable (see http://lists.mysql.org/mysql/101981 - "If you do not specify an ORDER BY clause, the order or records returned is undefined, i.e. random.")
I needed to ensure that stylesheets would come up in the same order each time, so what I came up with was a patch to lib/page.functions.php-
585c585
$cssquery = "SELECT css_text FROM ".cms_db_prefix()."css c, ".cms_db_prefix()."css_assoc ca
589c589,590
AND c.media_type = ?
> ORDER BY ca.create_date";
(cmdline: "diff -w stockinstall/lib/page.functions.php myver/lib/page.functions.php")
This patch causes multiple stylesheets to be output by get_stylesheet() in the time order that they were added to the template.
Same thing for admin/listcssassoc.php-
98c98
$query = "SELECT assoc_css_id, css_name FROM ".cms_db_prefix()."css_assoc ca INNER JOIN ".cms_db_prefix()."css ON assoc_css_id = css_id WHERE assoc_type=? AND assoc_to_id = ? ORDER BY ca.create_date";
(cmdline: "diff -w stockinstall/admin/listcssassoc.php myver/listcssassoc.php")
Not sure if this is a bug, feature request or WAD, but it helped me and mine. I'm not sure whether things like this should be posted to version control first - any guidance appreciated.
-sloop
When associating multiple stylesheets with a template, I've been finding that the order in which they appear at runtime, in the generated stylesheet, appears to vary.
In a stock 0.11.2 installation, I added three stylesheets to a template, and...
1) the order in which they appear on the template-stylesheet association page after adding (e.g. admin/listcssassoc.php?type=template&id=19) is not always consistent. it's not appearing in the order added anyway. after deleting and re-adding multiple times, i've seen the order change around;
2) the order of presentation on that page does seem to reflect the actual record order in the underlying MySQL table (css_assoc);
3) the order of output, when the template's stylesheet is generated (from the {stylesheet} tag) seems to reflect the table order, but whatever that is i don't know, no keys on that table. it's possible that on a clean CMS install into a fresh db, that add order will be correct; however after records are deleted and added, order in a MySQL table may be unpredictable (see http://lists.mysql.org/mysql/101981 - "If you do not specify an ORDER BY clause, the order or records returned is undefined, i.e. random.")
I needed to ensure that stylesheets would come up in the same order each time, so what I came up with was a patch to lib/page.functions.php-
585c585
$cssquery = "SELECT css_text FROM ".cms_db_prefix()."css c, ".cms_db_prefix()."css_assoc ca
589c589,590
AND c.media_type = ?
> ORDER BY ca.create_date";
(cmdline: "diff -w stockinstall/lib/page.functions.php myver/lib/page.functions.php")
This patch causes multiple stylesheets to be output by get_stylesheet() in the time order that they were added to the template.
Same thing for admin/listcssassoc.php-
98c98
$query = "SELECT assoc_css_id, css_name FROM ".cms_db_prefix()."css_assoc ca INNER JOIN ".cms_db_prefix()."css ON assoc_css_id = css_id WHERE assoc_type=? AND assoc_to_id = ? ORDER BY ca.create_date";
(cmdline: "diff -w stockinstall/admin/listcssassoc.php myver/listcssassoc.php")
Not sure if this is a bug, feature request or WAD, but it helped me and mine. I'm not sure whether things like this should be posted to version control first - any guidance appreciated.
-sloop