Search code examples
templatesjsfresourcesfaceletsconditional-rendering

Conditionally exclude a CSS resource file in template depending on template client


In my project, I have a main template page main_template.xhtml that has all the resource file includes.

I have a styles.css in the main template that contains styling classes of my pages. In one particular page I want to exclude the styles.css resource file, how can I achieve that?


Solution

  • As every other UI component, the <h:outputStylesheet> also supports the rendered attribute. You can grab the current view ID by UIViewRoot#getViewId() and just check on that.

    So, pieces put together that would look like:

    <h:outputStylesheet ... rendered="#{view.viewId ne '/specific.xhtml'}" />
    

    See also: