Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I maintain a theme called Tendu, and we are just now working on a function that does something similar.
Your implementation is far better then our current approach.
My question - Can this module / technique be implemented only with a function in template.php (+ the lines in the info file)?
I would love to add it as a part to my theme, but I don't want the theme to include a modules/ directory by default.
btw - how does your module handles sub-themes? any special behavior, or does it work just like regular added css file?
Thanks
Tom
Comment | File | Size | Author |
---|---|---|---|
#21 | conditional_styles-rtl_caching-337975-21.patch | 1.09 KB | alexanderpas |
#14 | rtl-337975-13.patch | 1.45 KB | JohnAlbin |
#11 | conditional_styles_rtl_094535.patch | 1.4 KB | apaderno |
#10 | conditional_styles_rtl_094534.patch | 1.4 KB | apaderno |
#9 | conditional_styles_rtl.patch | 1.4 KB | tombigel |
Comments
Comment #1
JohnAlbinWith sub-themes, the same rules apply to conditional stylesheets as to regular stylesheets. Sub-themes inherit the conditional stylesheets of their parent themes; and sub-themes can override or remove conditional stylesheets in the normal way.
And, yes, you can add this technique using a tendu_preprocess_page() and a tendu_theme() function. But its tricky. Zen 6.x-1.0-beta3 (and later) does this.
Comment #2
tombigel CreditAttribution: tombigel commentedThanks, I copied the relevant code from Zen and it works :)
One more question I forgot to ask:
In Drupal 6, when an RTL language is selected, for every stylesheet loaded Drupal looks for an additional stylesheet-rtl.css and adds it for incremental RTL changes right after it loads the regular stylesheet.
This rule does not apply to the stylesheets added by this module, I'll try to add it manually and post it here, but it should be a part of the module.
Comment #3
JohnAlbinUm… not sure. Can't check right this sec, so I'll re-open this issue so I don't forget to check later.
Comment #4
tombigel CreditAttribution: tombigel commentedHi again, I created a patch for automatically adding RTL CSS files when needed.
It was tested only on my local Tendu installation, I hope it works for you too.
I hope the patch is in the right format, never created one for a Drupal project myself.
Comment #5
JohnAlbinThanks for the patch! I'll take a look at it soon.
Comment #6
tombigel CreditAttribution: tombigel commentedbtw - The code with the patch is already integrated in Tendu version 2.x-dev and 2.x beta1
Comment #7
tombigel CreditAttribution: tombigel commentedFound a bug in my code:
If "locale" module is not enabled, the constants LANGUAGE_RTL / LANGUAGE_LTR are not defined.
I tried to replace this line in my patch:
With this line:
But it doesn't work.
I need help with this one...
Comment #8
tombigel CreditAttribution: tombigel commentedSorry my bad - it was supposed to be:
defined('LANGUAGE_RTL')
So this line:
Works!
Comment #9
tombigel CreditAttribution: tombigel commentedYou can't add a file when editing a comment here, so here's the updated patch...
Comment #10
apadernoRather than using all those backslashes to escape the string delimiter inside it, I would use a different string delimiter.
Comment #11
apadernoI changed a couple of string delimiters which should not have been changed.
Comment #12
tombigel CreditAttribution: tombigel commentedok.
I just copied their original "output .=" line...
Comment #13
JohnAlbinSo we have a choice of lots of
\"
or lots of' . '
in that line. Neither are ideal, but I still find the \" easier to read.Thanks for the patch, Tom! Can I get someone to confirm the patch in #9 actually works? :-)
Comment #14
JohnAlbinThis is the same as Tom's patch in #9 but conforms to Drupal's coding standards (with regards to spaces). Also, given how drupal_add_css() works, I've removed the check for
defined('LANGUAGE_RTL')
as it seems unnecessary.Comment #15
JohnAlbinTom, I just re-read your comment in #7 above, LANGUAGE_RTL and LANGUAGE_LTR are not defined in locale.module, they are defined during the bootstrap. http://api.drupal.org/api/constant/LANGUAGE_RTL/6
So, I don't understand what errors you were encountering.
Comment #16
JohnAlbinOk, I created a fake language for en-us that is RTL. Which, let me tell you, gives very interesting results. :-)
But its enough for me to test this patch. Everything seems to be working.
Thanks for the patch, Tom! http://drupal.org/cvs?commit=216204
Comment #17
tombigel CreditAttribution: tombigel commented@JohnAlbin: Maybe I was wrong about what caused the symptom, I just know what fixed it.
And anyway, checking whether a constant is defined before using it is better practice.
Comment #19
Anonymous (not verified) CreditAttribution: Anonymous commented@JohnAlbin Thank you for this useful module.
I'm sorry to reopen this issue but I experiencing problems with my rtl site although I'm using 6.x-1.1 and Tom recent rtl patch
if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL)
should work.my case:
- site has 2 languages enabled, one ltr and one rtl.
- the site default is the ltr one.
- rtl language negotiation set to path prefix only
- the module should load one of the files, ie6.css or ie7.css if on IE and if language is rtl then load it with it -rtl.css version.
the issue:
If the browser is IE (whether 6 or 7) then the conditional style always load both files (ie6.css and ie6-rtl.css) whether page language is rtl or ltr.
I tried to make the language condition at line 78 to be
$language->direction == LANGUAGE_RTL
but didn't work.I'm out of reasons why this module is working for me.
Comment #20
Anonymous (not verified) CreditAttribution: Anonymous commentedUpdate
The issue is clear now
The browser keeps conditional style load both files (ie6.css and ie6-rtl.css) whether page language is rtl or ltr until you "clear cache" from admin>settings>performance.
Once cache cleared you will have no -rtl.css at the ltr . BUT again it gets sticky once you switch to rtl and then it gets back to the first state with no difference (-rtl.css) loads whether on rtl or ltr page until you clear system cache.
drupal core similar functionality adds a dummy query string to keep forcing loads of new copy of files with the url change. http://api.drupal.org/api/function/drupal_get_css/6
$query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
Comment #21
alexanderpas CreditAttribution: alexanderpas commentedRTL cache overwrote LTR cache (or vice-versa)
this patch should fix it.
Comment #22
tombigel CreditAttribution: tombigel commented@aliadnan:
Weird, I haven't seen this behavior in any of the sites I built on Tendu, and never had a bug report about it.
On the other hand I never used "Path Prefix" in any of my sites. Does Drupal cache things differently in this case?
Or maybe you are doing something else like "Aggressive Mode" caching?
In any case, I'll mark the patch posted here as yet another thing I need to add to Tendu when I have the time... thanks.
Comment #23
JohnAlbin@alexanderpas Your logic looks sound. The cache is being written on a page with indeterminate language. It doesn't make sense to build the cache based only on whatever language happens to be currently active.
However, your patch in #21 doesn't work as the module never uses the new _rtl variable. I'm looking at this now.
When the cache is built, this module should always build a LTR and a RTL cache. And use the appropriate cache depending on whatever language is active on each page load.
Comment #24
JohnAlbinFixed. http://drupalcode.org/project/conditional_styles.git/commit/fe0dcdc