FoxCat

Summary: Using forms and fox to structure category and cross-group linking
Version:
Prerequisites: Fox
Status:
Maintainer: Pico
Categories: Fox Categories Forms
Discussion: FoxCat-Talk?

Questions answered by this recipe

  • How can I make it easier to add links to existing categories?
  • How can I make it easier to create relationships among pages, for example, to relate people, places and projects?
  • How can I keep the edit page view uncluttered by the markup used in this recipe?
  • How can I create picklists to select multiple items to be posted back to another page?

Description

The answers provided by this recipe require that you install the Fox recipe. The EditMore recipe is only required for the solution to the third question about hiding the markup from the edit page view.

I - The Basics: A drop down list for existing Categories

To make it easier to add links to existing categories, combine Fox's ability to post to the current page with a pagelist formatted as an input select form like this:

(:pagelist fmt=#selectpage group=Category name=-HomePage:)

Try the input select form, but note that it won't post links on this page because the Fox recipe is not enabled.

This solution involves three basic steps:

1. Add a PageListTemplate to format pagelist results into an input select Forms

[[#selectpage]]
(:template each:)(:input select pagelink[] "[[{=$FullName}|{=$Namespaced}]]" "{=$Namespaced}":)
(:template last:)(:input submit post "Add Link":)
[[#selectpageend]]

2. Add Fox markup and a pagelist to generate a working input select form that can post a link to a selected category page

(:fox selectcategory:)
(:foxtemplate "*{$$pagelink[]}":)
(:pagelist fmt=#selectpage group=Category name=-HomePage:)
(:foxend selectcategory:)

3. Add a heading and Fox directive to place and organize new category links

!!!Categories
(:foxprepend selectcategory:)

Try it (if Fox is enabled on this page, otherwise just read on to see what it should do)

  1. Select a category from the drop down form created in step 2 and the Add Link button.
    1. After the page refreshes you should see a link to the category page you selected.
  2. Click on that new category link.
    1. When the category page is displayed you should see a link back to this page (if the Category group was set up properly with a pagelist in the footer or header, see Categories).

Tweaking the basic solution

The example above uses a bare minimum of markup to make it easier to understand the core components. The following are several tweaks that you may want to consider.

Use GroupFooters

Move the Fox markup (from step 2) into the GroupFooter (or GroupHeader) to make it available on each page in a group. Use ConditionalMarkup to limit, or exclude, certain pages or users.

Use Fox's template options to make the posted links do more.

Enable posted links to be deleted without editing the page by changing the foxtemplate (in step 2 above) to:

(:foxtemplate *{$$pagelink[]}, {[foxdelline]}:)

If you want to limit who can see and use that link, include some conditional markup in the template, as described at Fox and at Cookbook:FoxSimpleTodoList.

Note, if a foxtemplate requires line breaks it can't be defined using the (:foxtemplate:) directive. The template will have to saved in separate page and identified using the template argument in the initial fox directive (:fox selectcategory template=pagename:). See Fox

Add an input box to create a new Category

At the end of fox markup (in step 2 above) add the following markup to create an input form that Fox will use to add a new page to the Category group

(:fox addcategory #top  foxgroup=Category:)
(:foxtemplate "":)
(:input text target value="" size=20:)
(:input submit post "New Category":)
(:foxend addcategory:)

Note: Fox requires some template in order to post a new page, so that is why the foxtemplate directive is used with a pair of quotation marks, or use template=0 in the fox markup, like for instance (:fox addcategory template=0:). If you want to specify the content of the new page, modify the foxtemplate directive, or use a separate template file and point to it using the template argument in the initial fox directive, as described above.

Select multiple Categories at once

To allow more than one Category to be selected at once change the pagelist template (in step 1 above).

To keep the input form working like a drop down list or menu, add both the "multiple" and "size" arguments, like this:

[[#selectpage]]
(:template each:)(:input select pagelink[] [[{=$FullName}|{=$Name}]] "{=$Titlespaced}" multiple size=3:)
(:template last:)(:input submit post Ok:)
[[#selectpageend]]

Note, when you use an input select with the multiple argument, selecting multiple items will require users to hold down the shift, or control keys while selecting items.

Troubleshooting: If multiple sections doen't end up posting more than one item, make sure that the square brackets were used in references to pagelink[] (above and) in Step 1 and {$$pagelink[]} in Step 2. Those square brackets specify that the variable uses an array. If it still doesn't work, make sure that you are using a current version of the Fox recipe. (Arrays were added in version 2007-09-24 with a bug fix in version 2007-10-21).

II - Beyond Categories: Relating various groups

The same concepts illustrated above for working with the Category group can be used for linking to other groups. Those other groups can be set up like categories, with pagelist markup in footers to cross-reference back to linking pages.

For each additional group, just copy the fox markup (from steps 2 and 3 above) and make the necessary adjustments. For example, if you create a group called "People", you could change "selectcategory" to selectpeople" and the pagelist argument from "group=Category" to "group=People" in step 2, and make similar changes to the heading and fox markup in step 3 to keep the links separated and organized. Note, you would not have to make any changes to the pagelist template (from step 1 above).

III - Displaying full picklists

The same approach used for linking to categories and cross-referencing amoung groups can also be used to provide pages that display full picklists. While such picklists might not make sense for adding categories and cross-referencing from other pages to the currently viewed page, they would make more sense for picking and choosing from a long list displayed on the viewed page and posting back to a different page (for example, back to the current author's profile page) using fox.

To make the input form expand into full listing of all items (losing the drop down effect), just add the "multiple" argument but leave off the "size" argument from the instructions about allowing multiple items to be selected at once. Specifically, change step2 to add the "multiple" argument:

[[#selectpage]]
(:template each:)(:input select pagelink[] [[{=$FullName}|{=$Name}]] "{=$Titlespaced}" multiple:)
(:template last:)(:input submit post Ok:)
[[#selectpageend]]

To make the selection of multiple items easier and more appropriate for a picklist function, change the input type from "select" to "checkbox," like this:

[[#selectpage]]
(:template each:)(:input checkbox pagelink[] "[[{=$FullName}|{=$Namespaced}]]":) {=$Namespaced}\\
(:template last:)(:input submit post "Ok":)
Note: you will need to end the line with "\\ or [[<<]] to keep items on separate lines (because we eliminated the starting asterisk "*" from the beginning of the line, which would have generated a list, but the asterisk and checkbox would not have looked good together.

IV - Moving markup out of the main editing screen

The EditMore recipe allows a portion of the page text to be moved out of the main editing screen into a separate text box for notes. In the editing screen, clicking the button labeled "show notes" causes a second text box to display. This may not seem like much of an advantage if you are using the basic set up, but if you start using the fox markup to create delete links, the underlying markup that will be generated can get pretty ugly and cluttered. If the wiki is intended to be edited by novice users, moving this markup off the main editing screen can make a big difference.

Note: Alternatively you could use FoxEdit, which lets you add edit links to a page and can open specific sections for editing, or an edit form showing a number of text fields for editing a number of page sections or page text variables. The trick is to create your fox posting form so it posts page text variables or anchored sections, which can then be used by FoxEdit as editing targets, if we may call them such. Thereby only the relevant information is loaded into an edit text box or textarea box.

Release Notes

20071208 Initial draft published

See Also

Contributors

Pico HansB

Comments

See discussion at FoxCat-Talk?