Web UI Framework

How to Show Theme Fragment Conditionaly

Updated: July 31, 2019 Page Information Edit on GitHub

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.

17 days ago Andrew Goodricke Syntax error fixed
4 years ago Manon Lumeau 28
5 years ago Solen Guitter 27
5 years ago Manon Lumeau 26
5 years ago Manon Lumeau 25
5 years ago Manon Lumeau 24
6 years ago Solen Guitter 23
6 years ago Solen Guitter 22
6 years ago Thibaud Arguillere 21
9 years ago Stéfane Fermigier 19
9 years ago Stéfane Fermigier 20 | Migrated to Confluence 4.0
9 years ago Stéfane Fermigier 18
9 years ago Stéfane Fermigier 17
9 years ago Stéfane Fermigier 16
9 years ago Stéfane Fermigier 15
9 years ago Stéfane Fermigier 14
9 years ago Stéfane Fermigier 13
9 years ago Stéfane Fermigier 12
9 years ago Stéfane Fermigier 11
9 years ago Stéfane Fermigier 10
9 years ago Stéfane Fermigier 9
9 years ago Stéfane Fermigier 8
9 years ago Stéfane Fermigier 7
9 years ago Stéfane Fermigier 6
9 years ago Stéfane Fermigier 5
9 years ago Stéfane Fermigier 4
9 years ago Stéfane Fermigier 3
9 years ago Stéfane Fermigier 2
9 years ago Stéfane Fermigier 1
History: Created by Stéfane Fermigier

We'd love to hear your thoughts!

All fields required