Feature Proposal: Add a new optional attribute to the META{"parent" ...} variable to limit number of upstream ancestors
Motivation
When a deeply nested Topic is viewed using the Pattern skin [or one of many skins that displays the META{"parent"} variable], the page is often rendered very wide, distorting the rest of the page's layout. The addition of an optional attribute (maxelements) is a small change, and completely backwards-compatible; any current unchanged uses of META{"parent"} will be unaffected.
Description
This change would add an optional attribute to the META{"parent"} variable - "maxelements". Once maxelements ancestors have been prepended to the list, all other ancestors are replaced by "...", thus limiting the length of the displayed list. Because the number of elements to be displayed is set on a per-use basis, developers can decide whether this added functionality is useful in a given context, and furthermore to what extent the context calls for the limiting of the ancestory list length.
--
OrrBernstein - 08 Mar 2005
Impact and Available Solutions
Note: Patch is attached as
https://www.twiki.org/p/pub/Codev/MetaParentOptionalLengthLimit/twiki-render-meta-parent-patch.diff. The patch is against the
TWikiProductionRelease of
02 Sep 2004 or
01 Sep 2004 (Cairo Release).
Documentation
The topic,
TWikiMetaData (#Rendering_Meta_Data), would need to be changed as such:
...
At present support is fairly basic:
| Variable usage: |
Comment: |
%META{"form"}% |
Show form data, see Form Templates |
%META{"attachments"}% |
Show attachments, excluding hidden ones. Options: all="on": Show all attachments i.e. including hidden ones |
%META{"moved"}% |
Details of any topic moves |
%META{"parent"}% |
Show topic parent. Options: dontrecurse="on": By default recurses up tree, this has some cost. nowebhome="on": Suppress WebHome. prefix="...": Prefix that goes before parents, but only if there are parents, default "". suffix="...": Suffix, only appears if there are parents, default "". separator="...": Separator between parents, default is " > ". maxelements="...": Maximum number of upstream ancestors before replacing the rest with "...", default is infinity. |
...
Examples
One example is putting the ancestory on the
WebTopBar, as a easy navigation mechanism if your TWiki has a good amount of hierarchical organization:
<div class="twikiLeft">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="170"<a href="%WIKILOGOURL%"><img src="%WIKILOGOIMG%" border="0" alt="Home"/></a></td>
<td valign="bottom" align="right"><br/><br/>[[%BASEWEB%.WebHome][Codev]] %META{"parent" nowebhome="on" prefix=" < " suffix="" maxelements="2"}% < <nop>%BASETOPIC%</td>
</tr>
</table>
</div>
<div class="twikiRight twikiSearchBox">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><label for="go">Jump: </label><input type="text" id="go" name="topic" size="16" /></td>
</tr>
</table>
</div>
Implementation
After reading in the new attribute,
...
my $maxElements = 0;
if( $args ) {
...
$maxElements = TWiki::extractNameValuePair( $args, "maxelements" );
}
...
we simply start counting how many elements we've seen - if we reach one past the max (note that we start counting at 0, so we've past the max when the count == the max specified), we add a "..." and break out of the loop.
...
my $elementCount = 0;
...
$elementCount += 1;
if( $elementCount == $maxElements ) {
$text = "...$sep$text";
last;
} else {
$text = "[[$pWeb.$pTopic][$pTopic]]$sep$text";
}
(this replaces: $text = "[[$pWeb.$pTopic][$pTopic]]$sep$text";)
...
Small change, but the effect on the visual effect of the trail is noticable.
Discussion: