Apache OFBiz Themes ==================== # What is a theme A Theme is an ofbiz component that defines all elements necessary to render all information generated by the screen engine through an embedded technology. Currently themes presents in Apache OFBiz use html5/jquery/css to do that. To realize that, a theme can define some properties, among them some can be necessary. It can define its own ftl macro to render the different modelScreen elements and can define its own screen decorator to prepare the final user screen structure for the technology used by the theme. # How to define it A theme is a standard component, present in the directory themes or plugins with a file definition present on widget/Theme.xml and support the [widget-theme.xsd](http://ofbiz.apache.org/dtds/widget-theme.xsd) To offer the possibility for end users to select the theme through the "Select Theme Screen", the theme need to load the entity VisualTheme and one or more entries related to this theme. # Structure of Theme.xml The theme definition file help OFBiz to know what specific rendering the Theme want to use. It's composed by two definition elements and four optional blocks ## Main definition The First mandatory element is one or several visualThemeId related to the theme Defined like that ```xml ``` You need to define in the database an entry in VisualTheme Entity for each visual-theme id defined. ```xml ``` >_Note_: a theme component can load one or more visual theme id. Usually only one is present. The second important (but not mandatory) element is **implements** ```xml ``` This element indicates that your theme copies from the extend theme all information not present in its file definition. If this element isn't present in your theme, you will need to define all information present in common-theme to be sure that OFBiz misses nothing for a correct run. Otherwise some functionnalities can be broken... >_Note_: It's highly recommended to extend the common-theme to be sure that your theme works correctly and to surcharge only what you need. The four following blocks are optionnal if you define an extends theme ## General properties This block contains all properties that the screen engine can use to prepare the rendering and that the theme can implement ```xml ``` ## Theme's specific properties This block contains all properties specific to this theme. In general these are some properties present on ftl template, that are initialized by the theme and can be surchaged by another theme through the extends elements. ```xml ``` ## Ftl macro library This block defines for each technology implemented by the screen engine where it can find the macro library for each model (Screen, Form, Tree, Menu) ```xml ... ``` >_Note_: If you want surcharge some macros, you can just create the desired macros and import the others from common-theme (at the top of file) like that : ```<#include "component://common-theme/template/macro/HtmlFormMacroLibrary.ftl"/>``` ## Screen library This block defines where OFBiz can find all official screens definitions in framework/common Normally, you don't need to change this file except if you need to define a default screen style that doesn't exist OOTB. If you need to extend an existing one, you have to do it in the theme directory. To define a new default screen style, you have to add it in this file, and point to the screen decorator in common-theme to define your default screen style as the default one. ```xml ... ... ``` Screens are separated in three types : * structural-decorator : contains all decorators that organise the screens structures * embed-decorator : decorator used only on sub screens * general-screen : list all generic inter applications screens # The common-theme This is the root theme that contains all information to ensure a good basic theme for OFBiz. Currently it keeps all old themes system for backward compatibility with ftl template managed by the entity **VisualThemeResource** # Create your own theme As a theme is a component, you can create a new theme like a plugin. After creating a component, you can add the two minimal information : * Theme.xml file in **plugins/my-theme/widget/** with minimal information : ```xml ``` * your data file to add your visual theme in **plugins/my-theme/data/** ```xml ``` The presence of VisualTheme entity helps to indicate which theme is available in your instance, specially helpful for tenant installations. To display your theme in OFBiz theme library, you can complete the information on each visual theme like ``` My new funny theme under nice tecnno ``` >_Note_: **display-name** and **description** support the flexibleStringExpander syntax ## extends common-theme This is a first step to understand how the theme system works. With your new theme, you can try to surchage different elements. To start, extends the common-theme : ```xml My new funny theme under nice tecnno ``` Now your theme should be operational, but without particularity. You can surcharge a ftl macro, to do this create your own ftl macro file in **plugins/my-theme/templates/macro/HtmlFormMacroLibrary.ftl** with ```ftl <#include "component://common-theme/template/macro/HtmlFormMacroLibrary.ftl"/> <#macro renderDisplayField type imageLocation idName description title class alert inPlaceEditorUrl="" inPlaceEditorParams=""> <#if description?has_content> *###*${description?replace("\n", "
")}**<#t/> <#else> *# #*<#t/> ``` Now indicate to your theme that you want use this library ```xml My new funny theme under nice tecnno ``` and check the result when you select your theme. The result isn't really interesting but it's to understand how it works. ## create from scratch TODO... # Backware compatibility with OFBiz 16.11 and above ## How themes worked before Before the theme management by model definition, all configurations have been present in the database through entity **VisualTheme** and **VisualThemeRessource**. These ressources were loaded in a **layoutProperties** variable and used directly by decorator screens and ftl templates. ## Now with the common-theme All this logic is still present in the common-theme template to keep backward compatibility, but the VisualThemeRessource is now useless and properties have been migrated to the Theme definition in the part **theme-properties** ### Example with BlueLight The blue light theme has been these properties in VisualThemeRessource : ```xml ``` Now it's just ```xml ``` And on theme definition ```xml ``` Values with **/images/...** have been moved to the common-theme that bluelight extends, the theme definition keeps only what the theme adds to the extended theme. >_Note_ property name supports the FlexibleMapAccessor syntax, so you can continue to populate a list (VT_STYLESHEET['add']), reset a list (VT_STYLESHEET[]) or add an element on the top list (VT_STYLESHEET[+0]) because some time the order libraries loading is important ### Migrate you own theme Easily, create you Theme.xml and move your VisualThemeResource in **theme-properties** like in the BlueLight example above. Maybe you will need to update your template because the modelTheme return ressources not always as list. So : `` -> return a String with `component://bluelight/template/Header.ftl` ` return a List