At line 1 added 31 lines |
The special {{[rsf:id|IDs]}} {{payload-component}} is reserved, and is designed to help out with the very common situation where otherwise one might need to create a {{[UIBranchContainer]}} containing a single component. |
|
The situation comes up quite often, where there is a piece of markup surrounding a component which is optional, which you want to suppress in addition to the component when the component is not there. For example, imagine the following bit of template: |
{{{ |
<span rsf:id="label-branch:">This is the description for <span rsf:id="component">My Component</span></span> |
}}} |
The component {{component}} (probably a UIOutput} is optional, and the [producer|ComponentProducer] may choose to leave it out. But without the branch here, what might be left behind is the text "This is the description for" which is clearly nonsensical. So, without {{payload-component}}, the conditional one would test in the producer would suppress the entire {{label-branch:}} as well as the {{component}} inside. |
|
{{{ |
if (showcomponent) { |
UIBranchContainer mybranch = UIBranchContainer.make(tofill, "label-branch:"); |
UIOutput.make(mybranch, "component", "My Component"); |
} |
}}} |
|
Considering that the ids for all branch containers are resolved within a global scope, this would be an increasing risk, as well as being very annoying. The special {{payload-component}} id lets us deal with this situation using only leaf components and only the original component in the producer. |
|
In the template, we apply the "real" id to the entire tag in the template that we want suppressed if the component is missing - and to the tag ''inside'' it which will actually peer with the component when it is present, we give the special id {{payload-component}} - like this: |
|
{{{ |
<span rsf:id="component">This is the description for <span rsf:id="payload-component">My Component</span></span> |
}}} |
This structure is "invisible" in the producer - we simply deal with the "real" component as follows: |
|
{{{ |
if (showcomponent) { |
UIOutput.make(tofill, "component, "My Component"); |
} |
}}} |
|
As of RSF 0.7, {{payload-component}} works with payloads which are both normal leaves and [repetitive leaves|RepetitiveLeaves]. |