Web UI Framework

How to Show Theme Fragment Conditionaly

Updated: July 31, 2019

A theme describes what you show and how you show it in your application. It is a set of pages, sections, cells and fragments. It is possible to show some fragment depending on some condition using perspective. A perspective is an attribute of the fragment element. If there is no perspective attribute, the fragment will be shown in all perspective. In a default Nuxeo Platform instance, there is only one perspective named default.

  1. First you need to register the perspective with:

    <extension target="org.nuxeo.theme.services.ThemeService"
        point="perspectives">
      <perspective name="myperspective">
        <title>perspective not to be shown all the time</title>
      </perspective>
    </extension>
    
    

    A perspective is just a name.

  2. then you add a perspective attribute to your fragment in the theme configuration:

    <!--this shows the fragment only in myperspective perspective.-->
    <fragment perspectives="myperspective" type="generic fragment"/>
    <!--this shows the fragment in myperspective and the default perspective. -->
    <fragment perspectives="myperspective,default" type="generic fragment"/>
    
    
  3. Finally, you add your own scheme to the perspective negociator to resolve the perspective:

    <extension target="org.nuxeo.theme.services.ThemeService" point="negotiations">
      <negotiation object="perspective" strategy="web"> <!--strategy is web for webengine and default for jsf-->
        <scheme>
          com.mycompany.mMnegociator  <!--here is you class-->
        </scheme>
      <!--don't forget to add the other perspective negociators -->
    </extension>
    
    

    Your class should implement the Scheme interface. The getOutcome method is passed a WebContext or a FacesContext. If you can't decide which perspective it is, return null, the query will be passed to the next negociator.

We'd love to hear your thoughts!

All fields required