module NewPage doesn't honour template selection
Forum » Wikidot features and bugs / Bugs and problems » module NewPage doesn't honour template selection
started by: andrewescottandrewescott
on: 1191751344|%e %b %Y, %H:%M %Z|agohover
number of posts: 8
rss icon RSS: new posts
summary:
When user creates new page via the NewPage module, and selects a template from the list provided, the selection is ignored and the last option in the list of templates is chosen instead.
module NewPage doesn't honour template selection
andrewescottandrewescott 1191751344|%e %b %Y, %H:%M %Z|agohover

In the nav:side panel of my wiki at 99sauces.wikidot.com, I have some code to allow users to quickly create a new page:

[[module NewPage size="15" template="template:person,template:place,template:producer" button="new page"]]

There are three templates listed, as users are meant to create only those pages relating to those templates. However, no matter which template the user selects, the Producer template is always used by the NewPage module.
unfold module NewPage doesn't honour template selection by andrewescottandrewescott, 1191751344|%e %b %Y, %H:%M %Z|agohover
Re: module NewPage doesn't honour template selection
hartnellhartnell 1191753692|%e %b %Y, %H:%M %Z|agohover

Let me check the docs. :) —hartnell

unfold Re: module NewPage doesn't honour template selection by hartnellhartnell, 1191753692|%e %b %Y, %H:%M %Z|agohover
Re: module NewPage doesn't honour template selection
hartnellhartnell 1191754098|%e %b %Y, %H:%M %Z|agohover

It's seems you did everything correctly. What happens when you include two or rather than three templates? —hartnell

unfold Re: module NewPage doesn't honour template selection by hartnellhartnell, 1191754098|%e %b %Y, %H:%M %Z|agohover
Re: module NewPage doesn't honour template selection
andrewescottandrewescott 1205319863|%e %b %Y, %H:%M %Z|agohover

Bit slow about responding, as I sort of hoped someone would fix this in the meantime, but that hasn't happened.

The problem still happens with two templates, but it doesn't happen with one template, i.e. this works fine:

[[module NewPage template="template:blah"]]

but this does not:

[[module NewPage template="template:blah, template:blah2"]]

In fact, after a bit of experimenting, it seems that if you provide multiple templates in the list, the last template is always the one used, no matter which one is chosen. (It doesn't matter whether there is a space after the comma or not.)

I've confirmed this using both Firefox 2 and IE 7.

If anyone else wants to test this, and assuming it's still there, I've got a scratch page up on the sandbox for this at http://sandbox.wikidot.com/show-templates

unfold Re: module NewPage doesn't honour template selection by andrewescottandrewescott, 1205319863|%e %b %Y, %H:%M %Z|agohover
Re: module NewPage doesn't honour template selection
andrewescottandrewescott 1205924672|%e %b %Y, %H:%M %Z|agohover

I've looked at the HTML generated by Wikidot for the http://sandbox.wikidot.com/show-templates page, and the problem becomes clearer..

<form action="dummy.html" method="get" onsubmit="WIKIDOT.modules.NewPageHelperModule.listeners.create(event)">
  <input class="text" name="pageName" type="text" size="30" maxlength="60" style="margin: 1px"/>
  <select name="template" style="margin: 1px">
    <option value="" selected="selected">-- Select a template --</option>
    <option value="254926">Cat1</option>
    <option value="294735">Breads</option>
    <option value="294768">Wines</option>
    <option value="5848">Rateit</option>
  </select>
  <input type="submit" class="button" value="create page" style="margin: 1px"/>
  <input type="hidden" name="template" value="5848"/>
</form>

Note that there are two form fields with the name "template": there's the select list and the hidden field. The hidden field is specifying the templateId for the last template in the list (Rateit), and over-rides any choice made by the user in the select list. The hidden field is normally used when there is a single template, pre-specified in the NewPage module, but should not be included when there are multiple templates.

unfold Re: module NewPage doesn't honour template selection by andrewescottandrewescott, 1205924672|%e %b %Y, %H:%M %Z|agohover
Re: module NewPage doesn't honour template selection
andrewescottandrewescott 1206012563|%e %b %Y, %H:%M %Z|agohover

Ok. I think I've found the bug. Looking in the Wikidot v1 source, the template file at /templates/modules/misc/NewPageHelperModule.tpl has the following code fragment:

{foreach from=$templates item=template}
      <option value="{$template->getPageId()}">{$template->getTitleOrUnixName()|escape}</option>
    {/foreach}
  </select>
{/if}
<input type="submit" class="button" value="{if $button}{$button|escape}{else}{t}create page{/t}{/if}" style="margin: 1px"/>
{if $categoryName}
  <input type="hidden" name="categoryName" value="{$categoryName}"/>
{/if}
{if $template}
  <input type="hidden" name="template" value="{$template->getPageId()}"/>

In the foreach loop, the variable $template is set to each of the entries of the $templates variable. Then, at the end of the code fragment, $template is still set to the last entry, so the hidden field is written out.

A solution would be to use a different variable name in the foreach loop instead of template, e.g. templateoption.

unfold Re: module NewPage doesn't honour template selection by andrewescottandrewescott, 1206012563|%e %b %Y, %H:%M %Z|agohover
Re: module NewPage doesn't honour template selection
GabrysGabrys 1209583926|%e %b %Y, %H:%M %Z|agohover

Thank you for this, we will adapt this patch (if you don't mind) soon.

Sorry for long inactivity from us, we're working on it now.


Piotr Gabryjeluk
visit my blog

last edited on 1209584040|%e %b %Y, %H:%M %Z|agohover by Gabrys + show more
unfold Re: module NewPage doesn't honour template selection by GabrysGabrys, 1209583926|%e %b %Y, %H:%M %Z|agohover
Re: module NewPage doesn't honour template selection
andrewescottandrewescott 1213705870|%e %b %Y, %H:%M %Z|agohover

Hi Gabrys.

I note that this is still not fixed (using the test page at http://sandbox.wikidot.com/show-templates). Surely it can't take this long to make the changes. If it were complex, I could understand, but this should take, literally, 30 seconds to modify the two lines of code in the three places required, and it would be done.

unfold Re: module NewPage doesn't honour template selection by andrewescottandrewescott, 1213705870|%e %b %Y, %H:%M %Z|agohover
new post

Bookmark and Share

Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.