File: blocks.html

package info (click to toggle)
cubictemp 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 264 kB
  • ctags: 139
  • sloc: python: 682; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 4,363 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta  content="text/html; charset=utf-8" http-equiv="Content-Type"/><link  href="static/yui/fonts/fonts.css" type="text/css" rel="StyleSheet"/>
<link  href="static/yui/reset/reset.css" type="text/css" rel="StyleSheet"/>
<link  href="static/yui/grids/grids.css" type="text/css" rel="StyleSheet"/>
<link  href="static/style.css" type="text/css" rel="StyleSheet"/>
<link  href="static/yui/base/base.css" type="text/css" rel="StyleSheet"/>
<link  href="docstyle.css" type="text/css" rel="StyleSheet"/>
<link  href="syntax.css" type="text/css" rel="StyleSheet"/>


<title>Cubictemp Manual - Blocks</title></head><body><div class="yui-t2" id="doc3"><div style="" id="hd"><h1> Cubictemp - Blocks </h1></div><div id="bd"><div id="yui-main"><div style="" class="yui-b"><h1>Named blocks</h1><p>Cubictemp blocks are chunks of text that are defined in the template body, and
can be referenced in various ways.  The simplest block variety is the <em>named
block</em>:</p><div class="highlight"><pre><span class="c">&lt;!--(block bar)--&gt;</span>
    The time has come the walrus said
<span class="c">&lt;!--(end)--&gt;</span>
one
@!bar!@
two
@!bar!@
three
</pre></div><p>Output:</p><pre class="output">
one
    The time has come the walrus said...
two
    The time has come the walrus said...
three
</pre><p>Like a function, named blocks only produce output when they are referenced. The
block definition itself does not appear in the template output.</p><p>Named blocks are callable objects that accept an over-riding namespace
argument:</p><div class="highlight"><pre><span class="c">&lt;!--(block bar)--&gt;</span>
    The time has come the @!foo!@ said...
<span class="c">&lt;!--(end)--&gt;</span>
@!bar(foo=&quot;walrus&quot;)!@

@!bar(foo=&quot;carpenter&quot;)!@
</pre></div><p>Output:</p><pre class="output">
    The time has come the walrus said

    The time has come the carpenter said
</pre><p>Blocks can be nested to arbitrary depths. Block namespaces and scopes work
similarly to Python namespaces and scopes.</p><p>Named blocks have the <b>_cubictemp_unescaped</b> attribute defined by default,
so they will go unescaped when inserted using the standard 
<code class="template">@!...!@</code> 
escaped substitution syntax.</p><h1> Repeat Blocks </h1><p>Cubictemp provides a repeat construct to allow traversal of iterables:</p><div class="highlight"><pre><span class="c">&lt;!--(for foo in bar)--&gt;</span>
    @!foo!@
<span class="c">&lt;!--(end)--&gt;</span>
</pre></div><p>Like a Python <strong>for</strong> loop, the template above loops through all elements of
"bar", setting the value of "foo" to each element in turn. As in simple
substitutions, any valid expression can be used as the sequence definition:</p><div class="highlight"><pre><span class="c">&lt;!--(for foo in range(3))--&gt;</span>
    Counting: @!foo!@
<span class="c">&lt;!--(end)--&gt;</span>
</pre></div><p>Output:</p><pre class="output">
Counting: 0
Counting: 1
Counting: 2
</pre><h1>Playing nice with your designers: closed and open tags</h1><p>There is a minor variation on the block definition syntax to help preserve
document structure during template design. Since the start and end directives
of Cubictemp blocks look like HTML comments, they are not visible when the
document is viewed as HTML. It is often convenient to be able to also comment
everything inside the block. This is accomplished using the <strong>open</strong> tag
variation:</p><div class="highlight"><pre><span class="c">&lt;!--(block foo)</span>
<span class="c">    The time has come the walrus said...</span>
<span class="c">(end)--&gt;</span>
</pre></div><p> There is no functional difference between the two flavours.</p></div></div><div style="" class="yui-b"><div class="pageindex"><ul><li class="inactive"><a href="index.html">Introduction</a></li><li class="inactive"><a href="subs.html">Tags</a></li><li class="active"><a href="blocks.html">Blocks</a></li><li class="inactive"><a href="processors.html">Processors</a></li><li class="inactive"><a href="api.html">API</a></li><li class="inactive"><a href="admin.html">Administrivia</a></li></ul></div></div></div><div style="" id="ft"><p>Copyright Nullcube 2008</p></div></div></body></html>