SID-01604: Including topics that utilize form data
| Status: |
Answered |
TWiki version: |
5.0.2 |
Perl version: |
|
| Category: |
CategoryApplications |
Server OS: |
|
Last update: |
13 years ago |
I'm building a TWiki application that utilizes several forms, templates, and formatted searches. One part of this application creates topics with an attached form and subsequently uses the form data to populate a command for copying and pasting into another system. The command is lengthy and fairly complex (thus the desire for automation), and I got it working by including it in the topic template. However, after the third time fixing a grammar problem in this statement (and therefore having to manually fix the command in all of the previously created topics), I decided that I should define the grammar in its own topic and include it in the template. This allows me to make corrections in a single place and update all of the previously created topics as well as the future ones.
At this point things started to get interesting as the grammar topic does not have the form, but the individual topics do. I was able to get it working by using:
%FORMFIELD{"Name" topic="%INCLUDINGTOPIC%"}%
However, now I'm creating a roll-up topic that uses search to include the command section from the various command topics. My search results return the commands, but they lack any of the form content - presumably due to my use of
INCLUDINGTOPIC.
So in a simplified form I have C -includes-> B(with form data) -includes-> A
How can I take the generic grammar from A, populate it with values from the form attached to B, and include the result in C?
--
JoshuaTharp - 2012-12-06
Discussion and Answer
Eureka!
With a little more experimentation, I think I have it figured out. Let me document what I've found for future reference.
Topic A
This is the topic with the grammar template. It has a number of lines, but the following two are typical.
%FORMFIELD{"Name" topic="%INCLUDINGTOPIC%"}%
%CALCULATE{$IF($NOT($EMPTY(%FORMFIELD{"Description" topic="%INCLUDINGTOPIC%"}%)), DESC '%FORMFIELD{"Description" topic="%INCLUDINGTOPIC%"}%')}%
The two key takeaways here:
- Use the topic parameter specifing
INCLUDINGTOPIC
- Use the SpreadSheetPlugin instead of VarIF - they do not behave similarly and while I could specify $formfield with VarIF, I could not figure out how to also specify the topic parameter

Is there an easier way to specify "If a form field has a value" than the $IF($NOT($EMPTY(formfield))) construct above?
Topic B
This is actually a template and a number of instances - one of these per command. Each has a form attached to it with several required and several optional values. As you can see from line 2 of Topic A if a form field is not provided, then I have to omit a portion of the grammar. Included in each instance Topic B is a section with the command included.
%STARTSECTION{"command"}%
<pre>
%INCLUDE{"CommandGrammar"}%
</pre>
%ENDSECTION{"command"}%
Topic C
This is my roll-up topic. It has a search that grabs all of the generated commands and puts them on one page for easy reference.
%SEARCH{
search="form[name='CommandForm']"
type="query"
nonoise="on"
format="$percntINCLUDE{\"$topic\" section=\"command\"}$percnt"}%
--
JoshuaTharp - 2012-12-06
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.