From e30858b91ea0c1759cd6bfd87ed1b4ca93c2ba4b Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Sat, 10 Nov 2012 22:47:55 +0100 Subject: [IMP] minor doc updates bzr revid: al@openerp.com-20121110214755-4x7skj4o2g2icx4l --- addons/web/doc/dev_qweb.rst | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 addons/web/doc/dev_qweb.rst (limited to 'addons/web/doc/dev_qweb.rst') diff --git a/addons/web/doc/dev_qweb.rst b/addons/web/doc/dev_qweb.rst new file mode 100644 index 00000000000..7ad1e20d57a --- /dev/null +++ b/addons/web/doc/dev_qweb.rst @@ -0,0 +1,79 @@ + +QWeb +==== + +QWeb is the template engine used by the OpenERP Web Client. It is a home made engine create by OpenERP developers. There are a few things to note about it: + +* Template are rendered in javascript on the client-side, the server does nothing. +* It is an xml template engine, like Facelets_ for example. The source file must be a valid xml. +* Templates are not interpreted. There are compiled to javascript. This makes them a lot faster to render, but sometimes harder to debug. +* Most of the time it is used through the Widget class, but you can also use it directly using *openerp.web.qweb.render()* . + +.. _Facelets: http://en.wikipedia.org/wiki/Facelets + +Here is a typical QWeb file: + +:: + + + + +
...
+
+ +
...
+
+
+ +A QWeb file contains multiple templates, they are simply identified by a name. + +Here is a sample QWeb template: + +:: + + +
+

Name:

+

Password:

+

This user is an Administrator

+ +

User has role:

+
+
+
+ + +*widget* is a variable given to the template engine by Widget sub-classes when they decide to render their associated template, it is simply *this*. Here is the corresponding Widget sub-class: + +:: + + UserPageWidget = openerp.base.Widget.extend({ + template: "UserPage", + init: function(parent) { + this._super(parent); + this.user_name = "Xavier"; + this.password = "lilo"; + this.is_admin = true; + this.roles = ["Web Developer", "IE Hater", "Steve Jobs Worshiper"]; + }, + }); + +It could output something like this: + +:: + +
+

Name: Xavier

+

Password:

+

This user is an Administrator

User has role: Web Developer

+

User has role: IE Hater

+

User has role: Steve Jobs Worshiper

+
+ +A QWeb template should always contain one unique root element to be used effectively with the Widget class, here it is a *
*. QWeb only react to ** elements or attributes prefixed by *t-*. The ** is simply a null element, it is only used when you need to use a *t-* attribute without outputting an html element at the same time. Here are the effects of the most common QWeb attributes: + +* *t-esc* outputs the result of the evaluation of the given javascript expression +* *t-att-ATTR* sets the value of the *ATTR* attribute to the result of the evaluation of the given javascript expression +* *t-if* outputs the element and its content only if the given javascript expression returns true +* *t-foreach* outputs as many times as contained in the list returned by the given javascript expression. For each iteration, a variable with the name defined by *t-as* contains the current element in the list. -- cgit v1.2.3