Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

WOComponentContent 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:

Code Block
xmlxml
titleParent
xml
<div>
  <wo:Child><em>Hello, World!</em></wo:Child>
</div>
xml
Code Block
xml
titleChild
xml
<p>
  <wo:WOComponentContent />
</p>

At run-time, the content between <wo:Child> and </wo:Child> is passed to Child and rendered in place of the WOComponentContent element:

xml
Code Block
xml
titleOutput
xml
<div>
  <p>
    <em>Hello, World!</em>
  </p>
</div>

...

We can overcome this limitation with ERXWOComponentContent and ERXWOTemplate. Firstly, the child component defines any number of regions for content from the parent using ERXWOComponentContent:

xml
Code Block
xml
titleChild
xml
<wo:ERXWOComponentContent templateName="first">
First default
</wo:ERXWOComponentContent><br/>
<wo:ERXWOComponentContent templateName="third">
Third default
</wo:ERXWOComponentContent><br/>
<wo:ERXWOComponentContent templateName="second">
Second default
</wo:ERXWOComponentContent>

The value for the templateName binding is arbitrary, and we use it to match the ERXWOComponentContent with its ERXWOTemplate.

xml
Code Block
xml
titleParent
xml
<div>
  <wo:Child>
    <wo:ERXWOTemplate templateName="third">
    Some <em>stuff</em> in the third template.
    </wo:ERXWOTemplate>
    <wo:ERXWOTemplate templateName="first">
    Some <em>stuff</em> in the first template.
    </wo:ERXWOTemplate>
  </wo:Child>
</div>

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:

xml
Code Block
xml
titleOutput
xml
<div>
  Some <em>stuff</em> in the first template.
  Some <em>stuff</em> in the third template.
  Second default
</div>