diff -r fd8751c3f3ee -r a721966779be doc/book/en/intro/tutorial/maintemplate.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/book/en/intro/tutorial/maintemplate.rst Thu May 07 16:33:22 2009 +0200 @@ -0,0 +1,131 @@ +.. -*- coding: utf-8 -*- + +Templates +--------- + +Look at ``cubicweb/web/views/basetemplates.py`` and you will +find the base templates used to generate HTML for your application. + +A page is composed as indicated on the schema below: + +.. image:: ../../images/lax-book.06-main-template-layout.en.png + +In this section we will demonstrate a change in one of the main +interesting template from the three you will look for, +that is to say, the HTMLPageHeader, the HTMLPageFooter +and the TheMainTemplate. + + +Customize a template +~~~~~~~~~~~~~~~~~~~~ + +Based on the diagram below, each template can be overriden +by your customized template. To do so, we recommand you create +a Python module ``blog.views.templates`` to keep it organized. +In this module you will have to import the parent class you are +interested as follows: :: + + from cubicweb.web.views.basetemplates import HTMLPageHeader, \ + HTMLPageFooter, TheMainTemplate + +and then create your sub-class:: + + class MyBlogHTMLPageHeader(HTMLPageHeader): + ... + +Customize header +````````````````` + +Let's now move the search box in the header and remove the login form +from the header. We'll show how to move it to the left column of the application. + +Let's say we do not want anymore the login menu to be in the header + +First, to remove the login menu, we just need to comment out the display of the +login graphic component such as follows: + +.. code-block :: python + + class MyBlogHTMLPageHeader(HTMLPageHeader): + + def main_header(self, view): + """build the top menu with authentification info and the rql box""" + self.w(u'
') + self.vreg.select_component('logo', self.req, self.rset).dispatch(w=self.w) + self.w(u' | \n') + # appliname and breadcrumbs + self.w(u'') + comp = self.vreg.select_component('appliname', self.req, self.rset) + if comp and comp.propval('visible'): + comp.dispatch(w=self.w) + comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view) + if comp and comp.propval('visible'): + comp.dispatch(w=self.w, view=view) + self.w(u' | ') + # logged user and help + #self.w(u'\n') + #comp = self.vreg.select_component('loggeduserlink', self.req, self.rset) + #comp.dispatch(w=self.w) + #self.w(u' | ') + + self.w(u' | ') + helpcomp = self.vreg.select_component('help', self.req, self.rset) + if helpcomp: # may not be available if Card is not defined in the schema + helpcomp.dispatch(w=self.w) + self.w(u' | ') + # lastcolumn + self.w(u'') + self.w(u' | \n') + self.w(u'