Tags:
create new tag
, view all tags

SID-02319: How to make an TWiki Application (simplier examples)?

Status: Answered Answered TWiki version: 6.0.2 Perl version:
Category: CategoryApplications Server OS: Last update: 49 minutes ago

I'm new on TWiki and fascinated by the possibilities of TWiki Applications. But the 'tutorials' on TWiki Applications look difficult and sometimes outdated, since new functions and VAR's were introduced.

So I started experimenting building my first TWiki Application on the SandboxWeb, called LibraryApplicationBaseTopic. What I'm trying to reach is the following: 1) The LibraryApplicationBaseTopic show a list of books, their title, author and location; 2) To add a new title (book), a user can press the 'Add book' button in this topic; 3) A new topic is generated, with an unique ID (Book-ID). In this topic the user can instantly fill in the LibraryApplicationBookForm with title, author and location of the newle added book. 4) Finally, of course, the newly added book is shown in the LibraryApplicationBaseTopic list of books.

Can anybody help me to make this work, with 'easy' and elegant code? For instance,I think is easier using VarEDITFORMFIELD now than te HTML form code. Mabey we can make this an example (or another example) of 'HowToMakeATWikiApplication'?

Feel free to use the related Sandbox topics.

-- Emiel Van Riel - 2017-06-19

Discussion and Answer

Hello Emiel,

A good idea to provide something to work with in the Sandbox web smile

over the years I've hacked together dozens of TWiki applications - so while it may look a bit confusing at the beginning, it gets easier once you have a working template. In your LibraryApplicationBaseTopic it was sufficient to make some minor corrections:

  1. The URL parameter for parenttopic must not be enclosed in quotes. With the quotes, TWiki "breaks" the link after parenttopic and thus misses the important templatetopic parameter.
  2. The action parameter should be form, not editform (See TWikiScripts).
  3. I've added a parameter excludetopic="*Template" to your SEARCH: Though the template topic has the form, it usually should not appear in the table.
  4. I've added a final vertical bar to your search format.

Another hint: You don't need the book id in your form. The user who adds a book is not supposed to supply an id because it is autogenerated, and you have the correct stanza $topic in your application topic to get the link to the new books expanded correctly. I've added one book, and it doesn't look too bad.

-- Harald Jörg - 2017-06-20

Hi Harald,

Thanks for helping.

  1. In LibraryApplicationBaseTopic I tried to hide some text with STARTSECTION. This doesn't seem to work.
  2. It looks like the Book topics are children of SandboxWeb, not of LibraryApplicationBaseTopic. Why does the "parenttopic=LibraryApplicationBaseTopic" in the EDIT-URL not work?
  3. To get back to list with books in LibraryApplicationBaseTopic, I added "redirectto=LibraryApplicationBaseTopic" to the EDIT-URL. This doe sn't seem to work either.
  4. When opening a Book topic (by clicking on the Book-ID in the book list), I want to see the Topic title ("Book-ID........") as Header1, then the editable form with title and author, and below that form the possibility to add topic content, like a comment on the book. Is this possible?
-- Emiel Van Riel - 2017-06-21

Hello Emiel,

Step by step:

  1. In LibraryApplicationBaseTopic I tried to hide some text with STARTSECTION. This doesn't seem to work.
    • I guess you are referring to LibraryApplicationBookTemplate? It seems that you've already found out how to fix that in rev. 3 of that topic. There was one blank in the wrong place.
  2. Why does the "parenttopic=LibraryApplicationBaseTopic" in the EDIT-URL not work?
    • TWikiScripts says that the parameter is topicparent instead of parenttopic. I should have noticed that earlier - sorry. However, if TWiki doesn't recognize a parent topic, it sets the parent to the topic from where you clicked on the "Add book" link - so it should "work as desired", and indeed all the books in your tests all have the parent topic set to your application base!
  3. To get back to list with books in LibraryApplicationBaseTopic, I added "redirectto=LibraryApplicationBaseTopic" to the EDIT-URL. This doesn't seem to word either.
    • You had a double quote before that last parameter. I removed that, and voila - it works now.
  4. When opening a Book topic (by clicking on the Book-ID in the book list), I want to see the Topictitle ("Book-ID........"), then the editable form with title and author, and below that form the possibility to add topic content, like a comment on the book. Is this possible?
    • Yes, this is possible.
      1. Topic title at the top: That's easy, just added it to the Template Topic (I've done this to LibraryApplicationBookTemplate).
      2. Editable form at the top: This can be done either with EDITFORMFIELD (check out the example in VarEDITFORMFIELD on how to add a "submit" button if you actually want to make changes), or with a PatternSkinCustomization (Section "I want to place the form at the top"), depending on how much control you want over the appearance. If you use the skin customization, you get the "traditional" TWiki form display.

Some more things to consider:

  • I've added a form to add a book, and stay on the page, to LibraryApplicationBaseTopic. You can just keep adding books without ever leaving the page. Note that the table will always show the new entries. This form could also provide hints how to add parameters to the save script which are invisible to the users, but required for your action.
  • I guess that author and title of a book seldom change. On your page template, you could use FORMFIELD instead of EDITFORMFIELD for those two and leave EDITFORMFIELD for the location parameter. If you really need to change the title because you made a typo, then the plain "edit" button on every TWiki page makes the traditional form available for change.
  • In your EDITFORMFIELD fields, you should add a value parameter like e.g. value=%FORMFIELD{"Author"}%, to display the current value of the field.
  • For collecting comments, check out the CommentPlugin (actually, we are seeing it at work here). Again, the COMMENTS macro needs to be added to the template topic. Using this feature, readers can add comments (somewhat restricted with regard to TWiki markup) without ever hitting the "edit" button.

-- Harald Jörg - 2017-06-21

Hello Harald,

Thanks again. This looks very much on what I had in mind.

  1. I deleted the Book-ID field from the Form, as you advised.
  2. I added a submit-button to LibraryApplicationBookTemplate. Changing the title, author or location works fine.
  3. When adding a book with the 'Add a book, stay on this page' option, all works fine. But using the 'Add book using the template' option doesn't seem to work. Is this pointing to the wrong template? Or has this to do with the 'action=form' command?
  4. At LibraryApplicationBaseTopic, is it possible to suppres the line "Search: form.name =.....", which is placed before te search result table?

-- Emiel Van Riel - 2017-06-22

Nice progress.

But using the 'Add book using the template' option doesn't seem to work. Is this pointing to the wrong template? Or has this to do with the 'action=form' command?

  • What doesn't seem to work? True, there is a difference to the "stay on page": Instead of your own submit button you have to use the "traditional" Save button. Apart from not displaying your submit button, this just works fine! As you assume, this has to do with 'action=form', but in particular it comes from calling the 'edit' script in your hyperlink. If you inspect the form you'll see that I directly invoke the save script! For hyperlinks, save doesn't work for security reasons, so if you don't want a form, your solution with a link to edit is quite fine.
...is it possible to suppress the line "Search: form.name =.....", which is placed before the search result table?
  • Sure. Amongst the gazillions of options in VarSEARCH there are some which suppress the bookkeeping information. Whenever I use a formatted search, I just add the catch-all nonoise="on" to the SEARCH parameters (I've done so in the Sandbox application).

Regarding the topic of a tutorial for writing applications: I just stumbled over Blog.BlogEntry201009x1 "How to Create a TWiki Application". It turns out that we ended up with something rather similar to Peter Thoeny's comment from 2013-10-09 smile

-- Harald Jörg - 2017-06-22

Thank you Harald for your help. I'll suggest at BlogEntry201009x1 "How to Create a TWiki Application" to make a link to our Library Application in the Sandbox.

-- Emiel Van Riel - 2017-07-17

      Change status to:
ALERT! 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.
SupportForm
Status Answered
Title How to make an TWiki Application (simplier examples)?
SupportCategory CategoryApplications
TWiki version 6.0.2
Server OS

Web server

Perl version

Browser & version

Edit | Attach | Watch | Print version | History: r8 < r7 < r6 < r5 < r4 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r8 - 2017-07-17 - EmielVanRiel
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.