Question
- One of my webs contains several categories like "Abbreviation" or "Documents".
- I have created several templates within a web, one for each category.
- Depending on the category, I want to preselect the corresponding template in WebTopicCreator in order to make it easier for the user.
- I know that I can provide special parameters to WebTopicCreator (at the moment it is only "parent").
- I want to give a parameter called topictemplate to WebTopicCreator.
- My question is: How can I change the code in WebTopicCreator in order to preselect the appropriate template within the selection box (the preselected one is "Default template" at the moment)?
Environment
--
KirstinWeber - 31 May 2007
Answer
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.
Good suggestion to add a template parameter. Just after
<select name="templatetopic" class="twikiSelect">
add this line:
%IF{"$templatetopic" then='<option value="%URLPARAM{templatetopic}%" selected="selected"></option>'}%
--
ArthurClemens - 31 May 2007
I tried it but it does not work. So I tried
<p>%STARTSECTION{"topictemplate"}%<select name="templatetopic">
<option value="">%MAKETEXT{"Default template"}%</option>%SEARCH{".*Template$" scope="topic" type="regex" nonoise="on" format="<option %IF{"$topictemplate=$topic" then=selected="selected"}%>$topic</option>"}%</select> <a href="%SCRIPTURL{view}%/TWiki06x01/WebTemplateTopics?web=%BASEWEB%">View templates</a> %ENDSECTION{"topictemplate"}%</p>
But it does not work either. I think the compare is wrong because if I do not compare templatetopic with $topic the last template of the selection is shown. But I do not know how to change the compare to be correct.
--
KirstinWeber - 01 Jun 2007
You need to escape the IF in the format so that it evaluates once per hit, and not just once per search:
format="<option $percntIF{\"$topictemplate=$topic\" then='selected=\"selected\"'}$percnt>$topic</option>"
--
PeterThoeny - 29 Jul 2007
Thanks. I replaced $topictemplate by %URLPARAM{topictemplate}% because I want to check the given parameter. Now it works but only if the parameter is given. Otherwise the comparision is not correct because %URLPARAM{topictemplate}% is empty. How can I manage the case if %URLPARAM{topictemplate}% is not given?
--
KirstinWeber - 31 Jul 2007
See
TWiki.VarURLPARAM for a description of URLPARAM's
default attribute, where you can give, well, a default value in case parameter is empty or missing.
--
HaraldJoerg - 31 Jul 2007
Great! Now it is working. I had some problems with using quotation marks but now it is working. Thanks to all of you for your help!
--
KirstinWeber - 01 Aug 2007