doc/book/en/B1060-templates.en.txt
changeset 288 487bcc269d50
parent 273 5b3f9e09a6ea
child 306 1ed1da008e50
equal deleted inserted replaced
287:adbf9a24c41e 288:487bcc269d50
       
     1 .. -*- coding: utf-8 -*-
       
     2 
       
     3 Templates
       
     4 =========
       
     5 
       
     6 [WRITE ME]
       
     7 
       
     8 * talk about main templates, etc.
       
     9 
       
    10 
       
    11 
       
    12 Look at ``cubicweb/web/views/basetemplates.py`` and you will
       
    13 find the base templates used to generate HTML for your application.
       
    14 
       
    15 A page is composed as indicated on the schema below :
       
    16 
       
    17 .. image:: images/lax-book.06-main-template-layout.en.png
       
    18 
       
    19 In this section we will go through a couple of the primary templates
       
    20 you must be interested in, that is to say, the HTMLPageHeader,
       
    21 the HTMLPageFooter and the TheMainTemplate.
       
    22 
       
    23 
       
    24 HTMLPageHeader
       
    25 --------------
       
    26 
       
    27 Customize header
       
    28 ~~~~~~~~~~~~~~~~
       
    29 
       
    30 Let's now move the search box in the header and remove the login form
       
    31 from the header. We'll show how to move it to the left column of the application.
       
    32 
       
    33 Let's say we do not want anymore the login menu to be in the header, but we 
       
    34 prefer it to be in the left column just below the logo. As the left column is
       
    35 rendered by ``TheMainTemplate``, we will show how to do it in TheMainTemplate_. 
       
    36 
       
    37 First, to remove the login menu, we just need to comment out the display of the
       
    38 login component such as follows : ::
       
    39 
       
    40   class MyHTMLPageHeader(HTMLPageHeader):
       
    41     
       
    42       def main_header(self, view):
       
    43           """build the top menu with authentification info and the rql box"""
       
    44           self.w(u'<table id="header"><tr>\n')
       
    45           self.w(u'<td id="firstcolumn">')
       
    46           self.vreg.select_component('logo', self.req, self.rset).dispatch(w=self.w)
       
    47           self.w(u'</td>\n')
       
    48           # appliname and breadcrumbs
       
    49           self.w(u'<td id="headtext">')
       
    50           comp = self.vreg.select_component('appliname', self.req, self.rset)
       
    51           if comp and comp.propval('visible'):
       
    52               comp.dispatch(w=self.w)
       
    53           comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view)
       
    54           if comp and comp.propval('visible'):
       
    55               comp.dispatch(w=self.w, view=view)
       
    56           self.w(u'</td>')
       
    57           # logged user and help
       
    58           #self.w(u'<td>\n')
       
    59           #comp = self.vreg.select_component('loggeduserlink', self.req, self.rset)
       
    60           #comp.dispatch(w=self.w)
       
    61           #self.w(u'</td><td>')
       
    62 
       
    63           self.w(u'<td>')
       
    64           helpcomp = self.vreg.select_component('help', self.req, self.rset)
       
    65           if helpcomp: # may not be available if Card is not defined in the schema
       
    66               helpcomp.dispatch(w=self.w)
       
    67           self.w(u'</td>')
       
    68           # lastcolumn
       
    69           self.w(u'<td id="lastcolumn">')
       
    70           self.w(u'</td>\n')
       
    71           self.w(u'</tr></table>\n')
       
    72           self.template('logform', rset=self.rset, id='popupLoginBox', klass='hidden',
       
    73                         title=False, message=False)
       
    74 
       
    75 
       
    76 
       
    77 .. image:: images/lax-book.06-header-no-login.en.png
       
    78 
       
    79 Let's now move the search box in the top-right header area. To do so, we will
       
    80 first create a method to get the search box display and insert it in the header
       
    81 table.
       
    82 
       
    83 ::
       
    84 
       
    85  from ginco.web.views.basetemplates import HTMLPageHeader
       
    86  class MyHTMLPageHeader(HTMLPageHeader):
       
    87     def main_header(self, view):
       
    88         """build the top menu with authentification info and the rql box"""
       
    89         self.w(u'<table id="header"><tr>\n')
       
    90         self.w(u'<td id="firstcolumn">')
       
    91         self.vreg.select_component('logo', self.req, self.rset).dispatch(w=self.w)
       
    92         self.w(u'</td>\n')
       
    93         # appliname and breadcrumbs
       
    94         self.w(u'<td id="headtext">')
       
    95         comp = self.vreg.select_component('appliname', self.req, self.rset)
       
    96         if comp and comp.propval('visible'):
       
    97             comp.dispatch(w=self.w)
       
    98         comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view)
       
    99         if comp and comp.propval('visible'):
       
   100             comp.dispatch(w=self.w, view=view)
       
   101         self.w(u'</td>')
       
   102         
       
   103         # logged user and help
       
   104         #self.w(u'<td>\n')
       
   105         #comp = self.vreg.select_component('loggeduserlink', self.req, self.rset)
       
   106         #comp.dispatch(w=self.w)
       
   107         #self.w(u'</td><td>')
       
   108         
       
   109         # search box
       
   110         self.w(u'<td>')
       
   111         self.get_searchbox(view, 'left')
       
   112         self.w(u'</td>')
       
   113 
       
   114         self.w(u'<td>')
       
   115         helpcomp = self.vreg.select_component('help', self.req, self.rset)
       
   116         if helpcomp: # may not be available if Card is not defined in the schema
       
   117             helpcomp.dispatch(w=self.w)
       
   118         self.w(u'</td>')
       
   119         # lastcolumn
       
   120         self.w(u'<td id="lastcolumn">')
       
   121         self.w(u'</td>\n')
       
   122         self.w(u'</tr></table>\n')
       
   123         self.template('logform', rset=self.rset, id='popupLoginBox', klass='hidden',
       
   124                       title=False, message=False)
       
   125 
       
   126     def get_searchbox(self, view, context):
       
   127         boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
       
   128                                                  view=view, context=context))
       
   129         if boxes:
       
   130             for box in boxes:
       
   131                 if box.id == 'search_box':
       
   132                     box.dispatch(w=self.w, view=view)
       
   133 
       
   134  
       
   135 
       
   136 
       
   137 HTMLPageFooter
       
   138 --------------
       
   139 
       
   140 If you want to change the footer for example, look
       
   141 for HTMLPageFooter and override it in your views file as in : 
       
   142 ::
       
   143 
       
   144   form ginco.web.views.basetemplates import HTMLPageFooter
       
   145   class MyHTMLPageFooter(HTMLPageFooter):
       
   146       def call(self, **kwargs):
       
   147           self.w(u'<div class="footer">')
       
   148           self.w(u'This website has been created with <a href="http://lax.logilab.org">LAX</a>.')
       
   149           self.w(u'</div>')
       
   150 
       
   151 Updating a view does not require any restart of the server. By reloading
       
   152 the page you can see your new page footer.
       
   153 
       
   154 
       
   155 TheMainTemplate
       
   156 ---------------
       
   157 .. _TheMainTemplate:
       
   158 
       
   159 The MainTemplate is a bit complex as it tries to accomodate many
       
   160 different cases. We are now about to go through it and cutomize entirely
       
   161 our application.
       
   162 
       
   163 TheMainTemplate is responsible for the general layout of the entire application. 
       
   164 It defines the template of ``id = main`` that is used by the application. Is 
       
   165 also defined in ``cubicweb/web/views/basetemplates.py`` another template that can
       
   166 be used based on TheMainTemplate called SimpleMainTemplate which does not have 
       
   167 a top section.
       
   168 
       
   169 .. image:: images/lax-book.06-simple-main-template.en.png
       
   170 
       
   171 CSS changes
       
   172 -----------
       
   173 
       
   174 We cannot modify the order in which the application is reading the CSS. In
       
   175 the case we want to create new CSS style, the best is to define it a in a new
       
   176 CSS located under ``myapp/data/``.
       
   177 
       
   178 If you want to modify an existing CSS styling property, you will have to use
       
   179 ``!important`` declaration to override the existing property. The application
       
   180 apply a higher priority on the default CSS and you can not change that. 
       
   181 Customized CSS will not be read first.
       
   182 
       
   183 1
       
   184 [TODO]
       
   185 Add login menu in left column
       
   186 
       
   187 
       
   188 [WRITE ME]
       
   189 
       
   190 * customize MainTemplate and show that everything in the user
       
   191   interface can be changed
       
   192 
       
   193 [TODO]
       
   194 Rajouter une section pour definir la terminologie utilisee.
       
   195 Dans ginco-doc rajouter une section pour cubciweb-ctl shell ou
       
   196 on liste les commandes dispos.