Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added notes about conditional comments for IE, from Howard's mailinsg list message this afternoon.

...

As with included JavaScript libraries, each stylesheet will only be added once, regardless of the number of components that include it via the annotation.

Conditionally Loading IE-Only Stylesheets

For Tapestry 5.2 and later, if you need to load a different stylesheet for Internet Explorer browsers, or for certain versions of IE browsers, you can use Tapestry's built-in support for IE conditional comments. Just add something like the following to your page or component (or layout) class:

Code Block
java
java

@Environmental
private JavaScriptSupport javaScriptSupport;
     
@Inject @Path("context:layout/ie-only.css")
private Asset ieOnlyStylesheet;

// add an IE-only style sheet if browser is IE
void afterRender() {
    javaScriptSupport.importStylesheet(new StylesheetLink(ieOnlyStylesheet, new StylesheetOptions(null, "IE")) );
}

The above will render something like:

Code Block
xml
xml

<!--[if IE]>
<link type="text/css" rel="stylesheet" href="/assets/1.0-SNAPSHOT/ctx/layout/ie-only.css"></link>
<![endif]-->