1
2
3
4
5
6
7
8
9
10
11
12
13 '''Nested namespace access
14
15 The 'with' tag is used to introduce nested namespaces.
16
17 The text enclosed in the with tag is rendered using information
18 from the given variable or expression.
19
20 For example, if the variable 'person' is bound to an object that
21 has attributes 'name' and 'age', then a 'with' tag like the
22 following can be used to access these attributes::
23
24 <!--#with person-->
25 <!--#var name-->,
26 <!--#var age-->
27 <!--#/with-->
28
29 Eather a 'name' or an 'expr' attribute may be used to specify data.
30 A 'mapping' attribute may be used to indicate that the given data
31 should be treated as mapping object, rather than as an object with
32 named attributes.
33
34 '''
35
36 __rcs_id__='$Id: DT_With.py 1069 2008-11-13 21:55:43Z stefan $'
37 __version__='$Revision: 1069 $'[11:-2]
38
39 from DT_Util import parse_params, name_param, InstanceDict, render_blocks, str
40 from DT_Util import TemplateDict
42 blockContinuations=()
43 name='with'
44 mapping=None
45 only=0
46
48 tname, args, section = blocks[0]
49 args=parse_params(args, name='', expr='', mapping=1, only=1)
50 name,expr=name_param(args,'with',1)
51 if expr is None: expr=name
52 else: expr=expr.eval
53 self.__name__, self.expr = name, expr
54 self.section=section.blocks
55 if args.has_key('mapping') and args['mapping']: self.mapping=1
56 if args.has_key('only') and args['only']: self.only=1
57
76
77 __call__=render
78