This question about Topic Markup Language and applications: Answered
How to determine the parent of an arbitrary topic?
I would like to extract the parent topic of an arbitrary topic, and the solutions I'm coming up with are really grotty. I'm creating a form which allows reparenting of a topic within a subset of existing topics, so need to put the topic name in a select list. The form will be
%INCLUDE%d
.
Initially, I thought
%META%
would do the trick, but it doesn't provide a
topic
parameter, so I can't simply do
%META{
"parent"
format="$topic"
topic="%INCLUDINGTOPIC%"
}%
Instead, I've resorted to this monster:
%SEARCH{
"parent.name"
type="query"
topic="%INCLUDINGTOPIC%"
format="$parent"
nonoise="on"
}%
which makes me cringe and seems like the proverbial sledge hammer, especially when wrapped in an
%IF%
:
%IF{ "'%INCLUDINGTOPIC%'/parent.name"
then="$percntSEARCH{ "parent.name" type="query" topic="%INCLUDINGTOPIC%" format="$parent" nonoise="on"}$percnt"
else="No Parent"
}%
(which is further stuck into a
default
parameter in
%FORMELEMENT%
).
I must be missing something obvious. If
%SEARCH%
is the way to go, a nice addition would be a parameter to it to specify a string to return if the search came up empty.
--
DiabJerius - 22 Jan 2010
Well, that last
%IF%
doesn't work anyway. What I really want to do is this (in pseudo-perl)
if ( defined $topic->parent )
output( $topic->parent->name )
else
output ( 'No Parent' )
endif
It's actually trickier, as I really want to output
$topic->parent->formfield('Name')
, as topic names are autogenerated and a "real" name is stored in the
Name
form field.
--
DiabJerius - 22 Jan 2010
I know it's no help, but 1.1 introduces the %QUERY macro to address precisely this sort of application. Your solution above is what I would have used pre 1.1.
--
CrawfordCurrie - 18 Mar 2010
See
HierarchicalNavigation for a working SEARCH to accomplish this on Foswiki 1.0.9 and earlier.
--
ArthurClemens - 23 Mar 2010