Version 7.1 by Pascal Robert on 2012/01/30 22:06

Show last authors
1 [[WOComponentContent>>http://wocommunity.org/documents/javadoc/WebObjects/5.4.2/com/webobjects/directtoweb/generation/WOComponentContentGeneration.html]] is the standard WebObjects dynamic element used to allow a sub-component to obtain content from its parent component. It acts as a marker in a sub-component to indicate where that content should be rendered. The content itself is the fragment between the child's opening and closing tags in the parent. For example, consider the following pair of components:
2
3 {{code title="Parent"}}
4
5 <div>
6 <wo:Child><em>Hello, World!</em></wo:Child>
7 </div>
8
9 {{/code}}
10
11 {{code title="Child"}}
12
13 <p>
14 <wo:WOComponentContent />
15 </p>
16
17 {{/code}}
18
19 At run-time, the content between ##<wo:Child>## and ##</wo:Child>## is passed to ##Child## and rendered in place of the ##WOComponentContent## element:
20
21 {{code title="Output"}}
22
23 <div>
24 <p>
25 <em>Hello, World!</em>
26 </p>
27 </div>
28
29 {{/code}}
30
31 The documentation for ##WOComponentContent## clearly describes its main limitation:
32
33 Note: You can only have one WOComponentContent element in a given component.
34
35 We can overcome this limitation with [[ERXWOComponentContent>>http://wocommunity.org/wonder/latest/api/er/extensions/components/ERXWOComponentContent.html]] and [[ERXWOTemplate>>http://wocommunity.org/wonder/latest/api/er/extensions/components/conditionals/ERXWOTemplate.html]]. Firstly, the child component defines any number of regions for content from the parent using ##ERXWOComponentContent##:
36
37 {{code title="Child"}}
38
39 <wo:ERXWOComponentContent templateName="first">
40 First default
41 </wo:ERXWOComponentContent><br/>
42 <wo:ERXWOComponentContent templateName="third">
43 Third default
44 </wo:ERXWOComponentContent><br/>
45 <wo:ERXWOComponentContent templateName="second">
46 Second default
47 </wo:ERXWOComponentContent>
48
49 {{/code}}
50
51 The value for the ##templateName## binding is arbitrary, and we use it to match the ##ERXWOComponentContent## with its ##ERXWOTemplate##.
52
53 {{code title="Parent"}}
54
55 <div>
56 <wo:Child>
57 <wo:ERXWOTemplate templateName="third">
58 Some <em>stuff</em> in the third template.
59 </wo:ERXWOTemplate>
60 <wo:ERXWOTemplate templateName="first">
61 Some <em>stuff</em> in the first template.
62 </wo:ERXWOTemplate>
63 </wo:Child>
64 </div>
65
66 {{/code}}
67
68 Note that the order of the ##ERXWOTemplate## components in the parent need not match the order of the ##ERXWOComponentContent## elements in the child (they are matched on the ##templateName## binding), and if the child finds no matching ##ERXWOTemplate##, the content within the ##ERXWOComponentContent## element itself is rendered to the output. In this example, the output would be:
69
70 {{code title="Output"}}
71
72 <div>
73 Some <em>stuff</em> in the first template.
74 Some <em>stuff</em> in the third template.
75 Second default
76 </div>
77
78 {{/code}}