BestPracticeTip19
Sub-Topics:-
BestPracticeTip19ViewTemplate | BestPracticeTip19aViewTemplate

Conditional automatic inclusion of Topic name and child topics in Topic header content

Pattern Skin Customization Problem

(i) If the WebTopicEditTemplate is used to pre-define the look and feel and layout of a new topic when it's created, it is possible for a user to accidentally delete the template code and spoil the sites consistency.

(ii) Child topics are not readily visible or accessible from the main topic view. It is cumbersome to review the "more topic actions" to find what "sub-topics" are associated with the current topic.

Context

(i) The out-of-the-box Foswiki Web Topics as written (Pattern skin), have a H1 format to the first line of the Topic. To get the same style on new topics either the user has to remember to use Heading 1 or the WebTopicEditTemplate has some dummy H1 holder for the user to edit, which can be erased.

(ii) Adding a search for child topics in the WebTopicEditTemplate too has its limitations with being accidentally deleted by a user.

Solution

Although the solution was created with the PatternSkin and SpacedWikiWordPlugin, the principal can be used on any skin to recreate the topic view template.

PatternSkin allows the inclusion of text before and after the contents of a topic. The context and details are in the PatternSkinCustomization topic.

Create your own user template for "view". There are three different ways to make use of the template code:
  1. Create a file view.my_skin.tml in your Foswiki's templates/ directory
  2. Store the template code in a topic, Eg. BestPracticeTip19ViewTemplate, then set the VIEW_TEMPLATE variable to the template topic in WebPreferences or Main.SitePreferences
       * Set VIEW_TEMPLATE = BestPracticeTip19View
  3. Take advantage of AutoViewTemplatePlugin (shipped with Foswiki 1.1) and attach forms to your topics, Eg. MyForm, which will automatically select a topic named MyViewTemplate to be used as the view template
  • Question for PaulHarvey about option 3:- would I be right to say that unless you attach a form to all existing topics, then only new topics with the form attached will adhere to the "new" template layout?-- BobCorless
  1. For testing, append ?template=Some.Topic to the URL of any Foswiki topic, Eg. /Support/BestPracticeTip19?template=Support.BestPracticeTip19View

________________________________

________________________________

Note, the IF statement all needs to be on the same line.

info Below is an alternative solution that's been re-formatted for readability. It also delays the SEARCH macro so that:
  • When the IF condition isn't selected, CPU time is preserved because the SEARCH isn't evaluated (Eg. on Web* topics)
  • The formatted search may produce any arbitrary output, including output that contains quotes

%TMPL:INCLUDE{"view"}% 
%TMPL:DEF{"contentheader"}%%IF{
  "'%TOPIC%'/lc(name) ~ 'web*'" 
  else="<h1>[[%TOPIC%]]</h1> 
    <h6>Sub-Topics:-</h6> 
    $percntSEARCH{
      \"parent.name='%TOPIC%'\"
      type=\"query\"
      nonoise=\"on\"
      format=\"[[$topic]]\"
      separator=\" | \" 
    }$percnt <hr/>"
}%%TMPL:END%
This has been saved to BestPracticeTip19ViewTemplate, and you can try it out by appending ?template=Support.BestPracticeTip19View to the URL of any Foswiki topic, examples:

And another template BestPracticeTip19aViewTemplate which includes a user defined css <style> for the Topic name and includes a background image and turns the anchor to a block.

Using this second template as an example, this topic is reformatted to look like this:-

info This animation requires a current version of JQueryPlugin. Try http://trunk.foswiki.org/Support/BestPracticeTip19 to see this animation

Animation

See also: http://trunk.foswiki.org/System/Macros#InsideOutLeftToRight

%IF{
  "'%TOPIC%'/lc(name) ~ 'web*'"
  else="<h1>[[%TOPIC%]]</h1>
    <h6>Sub-Topics:-</h6>
    $percntSEARCH{
      \"parent.name='%TOPIC%'\"
      type=\"query\"
      nonoise=\"on\"
      format=\"[[$topic]]\"
      separator=\" | \"
    }$percnt <hr/>"
}%
%IF{
  "'BestPracticeTip19'/lc(name) ~ 'web*'"
  else="<h1>[[%TOPIC%]]</h1>
    <h6>Sub-Topics:-</h6>
    $percntSEARCH{
      \"parent.name='%TOPIC%'\"
      type=\"query\"
      nonoise=\"on\"
      format=\"[[$topic]]\"
      separator=\" | \"
    }$percnt <hr/>"
}%
%IF{
  "'BestPracticeTip19'/lc(name) ~ 'web*'"
  else="<h1>[[BestPracticeTip19]]</h1>
    <h6>Sub-Topics:-</h6>
    $percntSEARCH{
      \"parent.name='%TOPIC%'\"
      type=\"query\"
      nonoise=\"on\"
      format=\"[[$topic]]\"
      separator=\" | \"
    }$percnt <hr/>"
}%
%IF{
  "'BestPracticeTip19'/lc(name) ~ 'web*'"
  else="<h1>[[BestPracticeTip19]]</h1>
    <h6>Sub-Topics:-</h6>
    $percntSEARCH{
      \"parent.name='BestPracticeTip19'\"
      type=\"query\"
      nonoise=\"on\"
      format=\"[[$topic]]\"
      separator=\" | \"
    }$percnt <hr/>"
}%
<h1>[[BestPracticeTip19]]</h1>
    <h6>Sub-Topics:-</h6>
    %SEARCH{
      "parent.name='BestPracticeTip19'"
      type="query"
      nonoise="on"
      format="[[$topic]]"
      separator=" | "
    }% <hr/>
<h1>[[BestPracticeTip19]]</h1>
    <h6>Sub-Topics:-</h6>
    [[BestPracticeTip19ViewTemplate]] | [[BestPracticeTip19aViewTemplate]] <hr/>

The use of an IF statement is (IMHO) the neat thing in that if the Topic is one of the "web" topics which are already formatted within the topic itself, then the text that would be normally displayed in the "contentheader" in all topics, is suppressed for the "web" topics. This prevents a "double" H1 appearing on the web topics. Although the IF topic suggests one cannot use single or double quotes in evaluation Macro{value}, I found it was fine.

So the above entry adds the "%TOPIC%" in H1 format at the top of the new post/topic, then runs a search for all children and provides links. This appears for any topic whose name doesn't begin with "web".

Known Uses

Simply topic creation with a standard (unalterable) template. Adding this in the contentheader allows any additional text or information to be added to all topics retrospectively. Using an INCLUDE or other pre-defined text within the WebTopicEditTemplate will lose the link when a new topic is created. Even if there was a neat way to keep dynamic links within a new topic, it is possible for the user to accidentally delete it.

Known Limitations

Example written to ignore Topics beginning with the word "Web"

See Also

PatternSkinCustomization, IfStatements, SkinTemplates, System.Macros, VarSEARCH, QuerySearch

BestPracticeTipsForm edit

Category Basic Topic Writing
I Attachment Action Size Date Who Comment
view.my_skin.tmpltmpl view.my_skin.tmpl manage 263 bytes 31 Aug 2010 - 00:15 BobCorless  
Topic revision: r4 - 25 Oct 2010, BobCorless
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy