create new tag
, view all tags

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

Status: Asked Asked TWiki version: 6.0.2 Perl version:
Category: CategoryTemplates Server OS: Last update: 6 days 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

      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.
Status Asked
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: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2017-10-12 - HaraldJoerg
  • 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.