Tags:
create new tag
, view all tags

SID-02334: Topic template (using VIEW_TEMPLATE) disables PatternSkin

Status: Answered Answered TWiki version: 6.0.2 Perl version:
Category: CategoryTemplates Server OS: Last update: 42 minutes ago

Experimenting with Topic templates as described in PatternSkinCustomization doesn't give me satisfying results. When I set the VIEW_TEMPLATE of a topic to MyViewTemplate (topic), the result doesn't look the same as the template topic. No menu structure, top menu or side bars show up. It seems to me that the Pattern skin/ view.pattern.tmpl isn't included in the new topic. PatternSkinCustomization says: "The topic template approach (using VIEW_TEMPLATE) ... We can use the same example as above. In a topic write: %TMPL:INCLUDE{"view"}% %TMPL:DEF{"top:toolbarbuttons"}%%TMPL:P{"more_link"}%%TMPL:END%" But: TWikiTemplates - How Template Directives Work, says: NOTE: Template directives work only for templates: they do not get processed in normal topic text. " How can I make MyViewTemplate work, so that my topic looks like MyViewTemplate, including the Pattern Skin styles, looks and menus?

-- Emiel Van Riel - 2017-10-06

Discussion and Answer

I'm not sure how much I can help here, but understanding PatternSkin (which is, as I use to say, more of an onion than a skin) is on my agenda, too. smile

  • The first thing to mention is that in the TWiki distribution, as well as on twiki.org, we don't see a pure PatternSkin at work. What we have is a setting of SKIN = tagme, topmenu, pattern - the tags and the top menu are bolted upon Pattern skin. The top menu doesn't exist in plain Pattern skin, but nevertheless the customization recipe should work.
  • Just to make sure: You should * Set VIEW_TEMPLATE = MyView, without the trailing Template.

Well, twiki.org is just another TWiki installation, so we can work on this live. I've created Sandbox.MyViewTest which uses Sandbox.MyViewTemplate. The template is pretty simple: It includes the "normal" view template as in the customization recipe, plus the modified top:toolbarbuttons from the recipe, and then plainly adds a sentence. And indeed, this sentence turns up in the test page on the bottom of the page! But where's the toolbar button? -- Well, there's where the non-Pattern skin comes into play: TopMenuSkin expands different blocks, and without investigating it in detail I guess that it doesn't expand top:toolbarbuttons at all. If you want to see this button, you need to fall back to vanilla Pattern skin like this: http://www.twiki.org/cgi-bin/view/Sandbox/MyViewTest?skin=pattern , overriding the default skin.

If this doesn't help, could you please try to modify Sandbox.MyViewTemplate and Sandbox.MyViewTest so that it doesn't work like you expect?

-- Harald Jörg - 2017-10-06

Template topics define only the default text for new topics. And template directives (like %TMPL:INCLUDE{"view"}%) work only for templates; they do not get processed in normal topic text. So when we set MyViewTemplate as VIEW_TEMPLATE, only the text of this topic is used. The templates "view" or "view.pattern" are not included.

Topic Templates are only to be used on topic creation. What I was looking for, is a way to display the content of the form of many topics in the same layout. Using %INCLUDE% doesn't work, since variables are expanded inside out. Including a 'layout template' with FORMFIELDS results in a topic with meta data of the form of the included ' layout template', not of the actual topic.

So I guess I have to create a view template as a master template. That might solve the problem.

(The topic ControlOverVariableExpansion is interesting, regarding INCLUDING topics).

-- Emiel Van Riel - 2017-10-12

Ok, now I understand better what you want to achieve, and I can give you some pointers. Creating a new master template is always a possible solution, but maybe it is not necessary to go that deep.

Template topics define only the default text for new topics. - well, that's not entirely correct. Templates are used at different stages in the process, and somewhat unfortunately both are called "Templates" (because, well, that's what they are).

  • There's the template topic used for topic creation: This is activated by using the templatetopic parameter of the save or edit script (see TWikiScripts). These topics define the initial topic text and form used with the topic, and template directives are not processed within them. In TWikiTemplates, these templates are called "Template Topics".
  • And there are the templates used for topic rendering: In TWikiTemplates, these templates are called "Master Templates". The VIEW_TEMPLATE setting belongs to this category. In Sandbox.MyViewTemplate I've made a change to demonstrate that the template directive which defines a block named aftertext is indeeed processed in Sandbox.MyViewTest. Note that in MyViewTemplate I've also explicitly included %TMPL:INCLUDE{"view"}% which provides you with view.pattern.tmpl and view.tmpl - maybe that is a notable difference to your efforts. After all, I didn't want to write a template from scratch, but just make a small change by redefining one block.

If I understand correctly you're mainly interested in formatting form fields for viewing. So, here are some pointers:

  • A simple trick to know is that the INCLUDE function has a parameter raw="on" which prevents variable expansion in the included topic. If you decide to include your form rendering code using FORMFIELD{...} in your template topic for topic creation, that's the way to go.
  • You might also want to have a look at EDITFORMFIELD which allows to not only render the form fields like you wish, but also to edit them. TWiki's Bugs web uses this to let users edit some, but not all fields in the form (see e.g. Bugs:Item7823). This does, however, not hide the form table, it only adds a new presentation.
  • For hiding the "traditional" table, PatternSkinCustomization has a helpful hint which can be exploited with the VIEW_TEMPLATE method: At the very end, there is a section I want to place the form at the top. To move the form to the top, the invocation %TMPL:P{"form"}% needs to be moved from the formbottom to the formtop block. Now, imagine that you have %TMPL:P{"form"}% in neither of the blocks: Whoops, the form table is gone!

-- Harald Jörg - 2017-10-12

Harald, thanks for your explanation. Some of the things you mention I found out myself already, but took me lots of time. Unfortunately, my goal seems to be out of reach with use of a VIEW_TEMPLATE. I solved this with a template in the TWiki template directory. What I did was the following:

  1. I created a template Mymetaview.tmpl:
%TMPL:DEF{"metaview"}%
This text can be changed to change the presentation of all topics containing Myform.
%TABLE{ sort="off" tableborder="0" tablewidth="80%" columnwidths="20%,80%" cellpadding="4" cellspacing="3" cellborder="0" headerbg="#e6e6e6" headercolor="#666666" databg="#d6d6d6, #e6e6e6" headerrows="2" footerrows="1" }%
%EDITFORMFIELD{ "form" type="start" action="save" topic=%TOPIC%}%
| Title | %EDITFORMFIELD{"Title" form="MyForm" value="%FORMFIELD{"Title"}%"}% |
| Summary | %EDITFORMFIELD{"Summary" form="MyForm" value="%FORMFIELD{"Summary"}%"}% |
| Docnumber | %EDITFORMFIELD{"Docnumber" form="MyForm" value="%FORMFIELD{"Docnumber"}%"}% |
| Author | %EDITFORMFIELD{"Author" form="MyForm" value="%FORMFIELD{"Author"}%"}% |
| Status | %EDITFORMFIELD{"Status" form="MyForm" value="%FORMFIELD{"Status"}%"}% |
|   | %EDITFORMFIELD{ "form" type="submit" value="Update fields in form after editing" }% |
%TMPL:END%

2. In the view template (view.tmpl, view.pattern.tmpl or view.myskin.tmpl) I included Mymetaview.tmpl if the TOPIC contains Myform:

%TMPL:INCLUDE{"Mymetaview.tmpl"}%
%TMPL:DEF{"content"}%
%IF{"form[name='MyForm']" then"$percntTMPL:P{$quotmetaview$quot}$percnt" else=""}%
%TEXT%
#TopicEnd%TMPL:END%

This does the trick. When Myform is added to a topic, the formfields are shown and can be changed. To change the looks of ALL topics with Myform, I only have to change Mymetaview.tmpl.

-- Emiel Van Riel - 2017-10-27

I am closing this question. However, I wonder if this should be documented somewhere else, e.g. in TWiki Applications chapter.

-- Emiel Van Riel - 2017-10-27

Indeed, the TWiki docs can be updated, it's a wiki. Please feel to enhance the docs in the TWiki web.

-- Peter Thoeny - 2017-10-28

Great that it works now as desired! On the plus side, this implementation doesn't even need to bother with VIEW_TEMPLATE settings. I also support Emiel's suggestion that a recipe to customize the appearance of form data would make a lot of sense.

The thing that you need to be aware with this solution is that you need to make the same changes again after a TWiki upgrade, which will probably overwrite view.tmpl and view.pattern.tmpl. If you want to avoid that, you can make your form appearance in your own TWiki data, using VIEW_TEMPLATE. As usual, I've set up a small demo in the Sandbox web: Sandbox.SID02334DemoTopic shows how a topic looks like, where Sandbox.MyForm is used as form and Sandbox.MyMetaViewTemplate contains the same customization as Emiel's Mymetaview.tmpl. In this demo, the VIEW_TEMPLATE setting is part of the topic text. This can either be automated in a TWiki application with a template topic which contains both the form and the setting, or by making the VIEW_TEMPLATE setting in the WebPreferences topics, so that it works for all topics. Emiel's implementation is clever enough not to affect topics which don't have the form in question. Of course, the contents of MyMetaViewTemplate could as well be written to a .tmpl file with the same effect. The difference between the two is that if it is in a topic, the appearance can be modified using TWiki's web interface, otherwise, you need access to the file system.

-- Harald Jörg - 2017-10-29

Thanks Harald for your last update. Now I have exactly what I wanted.

-- Emiel Van Riel - 2017-10-30

      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 Topic template (using VIEW_TEMPLATE) disables PatternSkin
SupportCategory CategoryTemplates
TWiki version 6.0.2
Server OS

Web server

Perl version

Browser & version

Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2017-10-30 - 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.