.. This file is a part of the AnyBlok project .. .. Copyright (C) 2017 Jean-Sebastien SUZANNE .. Copyright (C) 2021 Jean-Sebastien SUZANNE .. .. This Source Code Form is subject to the terms of the Mozilla Public License, .. v. 2.0. If a copy of the MPL was not distributed with this file,You can .. obtain one at http://mozilla.org/MPL/2.0/. .. AnyBlok documentation master file, created by sphinx-quickstart on Mon Feb 24 10:12:33 2014. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. .. contents:: Templating ========== FuretUI is a client, the goal of the serveur is to give the template to display the UI for the model. The template waiting by FuretUI is complexe and the anyblok_furetui give the helper to write easily these template. Define template in blok ----------------------- The first step is to load the template file:: class ABlok(Blok): furetui = { 'i18n': { 'en': {dict a translation} }, 'templates': [ 'path of the template file relative of the blok', ], } The extension has no importance, by convention the extension is tmpl for template, and the repository is templates at the root of the blok. The contenant of the template files is a html:: The base of the template ------------------------ Node : **template** ~~~~~~~~~~~~~~~~~~~ The attribute of the template are +-------------------------+-------------------------------------------------------------+ | Attribute's name | Description | +=========================+=============================================================+ | id | key to identify the template, the key is unique | +-------------------------+-------------------------------------------------------------+ | extend | Key to identify an existing template. | | | | | | * Alone this attibute allow to modify an existing template | | | * With attribute id, A new new template identify by id is a | | | modified copy of the extended template | +-------------------------+-------------------------------------------------------------+ | rewrite | The id of a template is unique and can be reuse directly to | | | create another template or rewrite. This attribute allow to | | | replace an existing template by another one | +-------------------------+-------------------------------------------------------------+ Node : **call** ~~~~~~~~~~~~~~~ The node **call** allow to include a template in another template:: the result will be:: This template can be shared between more than one another template Node : **xpath** ~~~~~~~~~~~~~~~~ This Node works with the attribute **extend** of the template node. The goal is to modify a curent template with modification given by xpath:: +----------------------------+---------------------------------------------------------+ | Attribute | Description | +============================+=========================================================+ | expression | xpath expression defined by | | | `lxml _` | +----------------------------+---------------------------------------------------------+ | action | The action to do, see next table | +----------------------------+---------------------------------------------------------+ | mult | Boolean (default : False), If True All the node will be | | | modified, else only the first | +----------------------------+---------------------------------------------------------+ +----------------------------+---------------------------------------------------------+ | action | Description | +============================+=========================================================+ | insert | Insert the element in the selected node | +----------------------------+---------------------------------------------------------+ | insertBefore | Insert the element before the selected node | +----------------------------+---------------------------------------------------------+ | insertAfter | Insert the element after the selected node | +----------------------------+---------------------------------------------------------+ | replace | Insert the element at the location of the seleted node | +----------------------------+---------------------------------------------------------+ | remove | Remove the seleted node | +----------------------------+---------------------------------------------------------+ | attributes | Replace some attributes of the selected node | +----------------------------+---------------------------------------------------------+ Example of xpath attributes:: Node : **field** ~~~~~~~~~~~~~~~~ This node is particulare, because it is used by the resource representation, the attribute depend of the resource type Template : **List** ------------------- Example of list resource:: **field** attributes ~~~~~~~~~~~~~~~~~~~~ This attributes are used by all the field widgets +----------------------------+---------------------------------------------------------+ | attribute | Description | +============================+=========================================================+ | name | Required, name of the field to display | +----------------------------+---------------------------------------------------------+ | sortable | The field is sortable, in the case of the relationship | | | the value can be a string "field name.sub field name" | +----------------------------+---------------------------------------------------------+ | label | Label to display in column header | +----------------------------+---------------------------------------------------------+ | widget | Type of field to display, by default is the type of the | | | field | +----------------------------+---------------------------------------------------------+ | tooltip | Tooltip for the column | +----------------------------+---------------------------------------------------------+ | width | the column size | +----------------------------+---------------------------------------------------------+ | hidden | Can be evaluate, if True the the column will not be | | | displaied | +----------------------------+---------------------------------------------------------+ | column-can-be-hidden | The column can be hidden, an option is shown at the | | | top of the list | +----------------------------+---------------------------------------------------------+ | hidden-column | works with **column-can-be-hidden**, this attribute | | | give a default value to hide or display column | +----------------------------+---------------------------------------------------------+ slot ~~~~ The display of the field can modified:: The value is : {{ value }} We also use another field in the slot::