cogA way to display data, from an xwiki application, with bootstrap style tabs and tooltip + an application example in Sandbox space
Developed by

Pascal Bastien

0 Votes
LicenseDo What The Fuck You Want To Public License 2

Tested from xWiki 6.4 to 7.0.1 with flamingo skin.



I have an xWiki application with data and I want simply add tabs presentation and tooltip help.
This page is more an howto doc about xwiki application rendering than an extension.
My Xar extension BootstrapTabExample-0.9.xar provide 4 pages in Sandbox space: BootstrapTabExample, BootstrapTabClass, BootstrapTabSheet and BootstrapTabTemplate.


  • a nice application under Sandbox space with a Class BootstrapTabClass, Template BootstrapTabTemplate and Sheet BootstrapTabSheet
  • some CSS instruction to display tabs and tooltips in a  XWiki.StyleSheetExtension Objects attached to the Sheet BootstrapTabSheet
  • some javascript code to save last opened tab when we edit or view a page to stay on same opened tab in an XWiki.JavaScriptExtension object attached to the Sheet BootstrapTabSheet
  • some short CSS instruction to apply only in view mode in an XWiki.StyleSheetExtension Objects attached to the Class by example BootstrapTabClass
  • and finally some velocity instruction in my BootstrapTabSheet to display HTML code or not depending of property name.


Here velocity code in my BootstrapTabSheet sheet:

## tab and table CSS
#set($discard = $xwiki.ssx.use("Sandbox.BootstrapTabSheet"))
#if ($xcontext.action == 'view')
  ## Apply a specific CSS style in view mode (to hide tooltip icone)
  #set($discard = $xwiki.ssx.use("Sandbox.BootstrapTabClass"))

## Javascript to drop a cookie to save last opened tab
#set($discard = $xwiki.jsx.use("Sandbox.BootstrapTabSheet"))

##Prefix to identify HTML code to display it
#set ($PrefxHtml= 'CodeH')

{{html wiki="true"}}

## Class to use
#set($class = $doc.getObject('Sandbox.BootstrapTabClass').xWikiClass)
## loop on Class properties
#foreach($prop in $
  ## display HTML code (stored in Prettyname property) for tab and container
  #if ($prop.Name.startsWith("$!{PrefxHtml}_")=='true')
    ##Insert HTML code inserted in the property PrettyName
    #set ($StrLine= $prop.prettyName)
    ##display data in a table
    ##start the line
    #set ($StrLine= "<div class='BstRow'>")
    #if ($stringtool.trimToEmpty($prop.prettyName)!='')
      ## display PrettyName in first Column
      #set ($StrLine= $!StrLine+"<div class='BstColumn1'>$prop.prettyName</div>")
    ## display data in second Column
    ## #set ($StrLine= $!StrLine+" <div class='BstColumn2 BstViewValue'>$doc.display($prop.getName())</div>")
    #set ($StrLine= $!StrLine+" <div class='BstColumn2 BstViewValue " + $classWidthColumn + "'>$doc.display($prop.getName())</div>")
    ## end of the line
    #set ($StrLine= $!StrLine+"</div>")
  ## display the table line
  ## and reinit it
  #set ($StrLine='')



How is it working ?

I use a classic loop to display all my field/properties but I insert some HTML code for tab and tooltips. 


I use a classic loop to display all my field/properties except for field who's the name starting with 'CodeH_' string. In this case, I display only the PrettyName value. This PrettyName value of this specific field contains of course HTML code for my tabs (and bloc).
For this property I use Computed Field type property because it is unnecessary to store data in this field.

  • Here, first HTML code to display all tabs on top of page:
    <div class="tabs"><ul class="nav nav-tabs"><li><a data-toggle="tab" href="#P1"><span class="Down">&#x25BC;</span> Tab one</a></li><li><a data-toggle="tab" href="#P2"><span class="Down">&#x25BC;</span> Tab two</a></li><li><a data-toggle="tab" href="#P9"><span class="Down">&#x25BC;</span> My last tab</a></li></ul><div class="tab-content"><div id="P1" class="tab-pane fade in active"><h4>My Tab one H4 title</h4><DIV Id="TabP1" Class="container"><div class="Bloc"><div class="BlocTitle">My bloc title</div> 
  • and HTML code to start a new tab:
    <div id="P2" class="tab-pane fade"><h4>Another Comment with large width</h4><DIV Id="TabP2" Class="container">

Here a screenshot of BootstrapTabClass and result to understand better:



To display tooltips, in BootstrapTabClass I paste in the PrettyName of a property this HTML span tag code:
My PrettyName <span class="BtsHelp yellow-tooltip" rel="tooltip"  data-toggle="tooltip" data-placement="bottom" title="Text displayed in tooltip"> icon:lightbulb </span>

Large column

If I want display a data (e.g a textarea comment) on full width of the page, I simply don't fill PrettyName of the property and BootstrapTabSheet will display data on one column.



Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes


Version 0.9 (Initial version)

Tags: tab code
Created by Pascal Bastien on 2015/05/05 16:23

Get Connected