Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
172 ashish 1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
2
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml"
4
	xmlns:py="http://genshi.edgewall.org/"
5
	xmlns:xi="http://www.w3.org/2001/XInclude">
6
 
7
<xi:include href="master.html" />
8
 
9
<head>
10
<meta content="text/html; charset=UTF-8" http-equiv="content-type"
11
	py:replace="''" />
12
<title>Learning TurboGears 2.0: Quick guide to the Quickstart
13
pages.</title>
14
</head>
15
 
16
<body>
17
${sidebar_top()} ${sidebar_bottom()}
18
<div id="getting_started">
19
<h2>Architectural basics of a quickstart TG2 site with some vars
20
${val1} and ${val2}.</h2>
21
<p>The TG2 quickstart command produces this basic TG site. Here's
22
how it works.</p>
23
<ol id="getting_started_steps">
24
	<li class="getting_started">
25
	<h3>Code my data model</h3>
26
	<p>When you want a model for storing favorite links or wiki
27
	content, the <strong>/model</strong> folder in your site is ready to
28
	go.</p>
29
	<p>You can build a dynamic site without any data model at all.
30
	There still be a default data-model template for you if you didn't
31
	enable authentication and authorization in quickstart. If you enabled
32
	it, you got auth data-model made for you.</p>
33
	</li>
34
	<li class="getting_started">
35
	<h3>Design my URL structure</h3>
36
	<p>The "<span class="code">root.py</span>" file under the <strong>/controllers</strong>
37
	folder has your URLs. When you called this url (<span class="code"><a
38
		href="${tg.url('/about')}">about</a></span>), the command went through the
39
	RootController class to the <span class="code">about</span><span
40
		class="code">()</span> method.</p>
41
	<p>Those Python methods are responsible to create the dictionary of
42
	variables that will be used in your web views (template).</p>
43
	</li>
44
	<li class="getting_started">
45
	<h3>Reuse the web page elements</h3>
46
	<p>A web page viewed by user could be constructed by single or
47
	several reusable templates under <strong>/templates</strong>. Take
48
	'about' page for example, each reusable templates generating a part of
49
	the page. We'll cover them in the order of where they are found, listed
50
	near the top of the about.html template</p>
51
	<p><strong><span class="code">header.html</span></strong> - The
52
	"header.html" template contains the HTML code to display the 'header':
53
	The blue gradient, TG2 logo, and some site text at the top of every
54
	page it is included on. When the "about.html" template is called, it
55
	includes this "header.html" template (and the others) with a <span
56
		class="code">&lt;xi:include /&gt;</span> tag, part of the Genshi
57
	templating system. The "header.html" template is not a completely
58
	static HTML -- it also dynamically displays the current page name with
59
	a Genshi template method called "replace" with the code: <span
60
		class="code">&lt;span py:replace="page"/&gt;</span>. It means replace
61
	this <span class="code">&lt;span /&gt;</span> region with the contents
62
	found in the variable 'page' that has been sent in the dictionary to
63
	this "about.html" template, and is available through that namespace for
64
	use by this "header.html" template. That's how it changes in the header
65
	depending on what page you are visiting.</p>
66
	<p><strong><span class="code">sidebars.html</span></strong> - The
67
	sidebars (navigation areas on the right side of the page) are generated
68
	as two separate <span class="code">py:def</span> blocks in the
69
	"sidebars.html" template. The <span class="code">py:def</span>
70
	construct is best thought of as a "macro" code... a simple way to
71
	separate and reuse common code snippets. All it takes to include these
72
	on the "about.html" page template is to write <span class="code">
73
	<br />
74
	<br />
75
	$${sidebar_top()} <br />
76
	$${sidebar_bottom()} <br />
77
	<br />
78
	</span> in the page where they are wanted. CSS styling (in
79
	"/public/css/style.css") floats them off to the right side. You can
80
	remove a sidebar or add more of them, and the CSS will place them one
81
	atop the other.</p>
82
	<p>This is, of course, also exactly how the header and footer
83
	templates are also displayed in their proper places, but we'll cover
84
	that in the "master.html" template below.</p>
85
	<p>Oh, and in sidebar_top we've added a dynamic menu that shows the
86
	link to this page at the top when you're at the "index" page, and shows
87
	a link to the Home (index) page when you're here. Study the
88
	"sidebars.html" template to see how we used <span class="code">py:choose</span>
89
	for that.</p>
90
	<p><strong><span class="code">footer.html</span></strong> - The
91
	"footer.html" block is simple, but also utilizes a special "replace"
92
	method to set the current YEAR in the footer copyright message. The
93
	code is: <span class="code">&lt;span
94
	py:replace="now.strftime('%Y')"&gt; </span> and it uses the variable "now"
95
	that was passed in with the dictionary of variables. But because "now"
96
	is a datetime object, we can use the Python <span class="code">"strftime()"</span>
97
	method with the "replace" call to say "Just Display The Year Here".
98
	Simple, elegant; we format the date display in the template (the View
99
	in the Model/View/Controller architecture) rather than formatting it in
100
	the Controller method and sending it to the template as a string
101
	variable.</p>
102
	<p><strong><span class="code">master.html</span></strong> - The
103
	"master.html" template is called last, by design. The "master.html"
104
	template controls the overall design of the page we're looking at,
105
	calling first the "header" py:def macro, then the putting everything
106
	from this "about.html" template into the "content" div, and then
107
	calling the "footer" macro at the end. Thus the "master.html" template
108
	provides the overall architecture for each page in this site.</p>
109
	<p>But why then shouldn't we call it first? Isn't it the most
110
	important? Perhaps, but that's precisely why we call it LAST. The
111
	"master.html" template needs to know where to find everything else,
112
	everything that it will use in py:def macros to build the page. So that
113
	means we call the other templates first, and then call "master.html".</p>
114
	<p>There's more to the "master.html" template... study it to see
115
	how the &lt;title&gt; tags and static JS and CSS files are brought into
116
	the page. Templating with Genshi is a powerful tool and we've only
117
	scratched the surface. There are also a few little CSS tricks hidden in
118
	these pages, like the use of a "clearingdiv" to make sure that your
119
	footer stays below the sidebars and always looks right. That's not TG2
120
	at work, just CSS. You'll need all your skills to build a fine web app,
121
	but TG2 will make the hard parts easier so that you can concentrate
122
	more on good design and content rather than struggling with mechanics.</p>
123
	</li>
124
</ol>
125
<p>Good luck with TurboGears 2!</p>
126
</div>
127
</body>
128
</html>