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
Stylesheet order - get_stylesheet()
Re: Stylesheet order - get_stylesheet()
Thanks for the patch! It is a bug and as far as I know it is a known problem. IMHO, the correct solution would be to have a user definable order: css stanza's are allowed to override eachother so the order of each snippet is important for the final layout. But fixing the order is better than no predictable order at all.
Re: Stylesheet order - get_stylesheet()
Thanks for the simple patch. It's going into svn right now. I agree that ordering is a major oversight, but it's a little too late in the release cycle to add something as significant without doing another beta.
Thanks again!
Thanks again!