Item11400: Add default param values to TMPL:DEF.
Priority: Enhancement
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component:
Branches: trunk
Case at hand:
%TMPL:DEF{"startsection"}%
<div class='foswikiSection %class%'>
%TMPL:END%
...
%TMPL:P{"startsection"}%
This creates a problem: when
TMPL:P{"startsection"}
is not called with parameter
class
, the
%class%
string will remain in the rendered text.
It would be much better to be able to set a default value like:
%TMPL:DEF{"startsection" class=""}%
<div class='foswikiSection %class%'>
%TMPL:END%
...
%TMPL:P{"startsection"}%
This would allow for more creative uses as well:
%TMPL:DEF{"conditional" tmpl="default"}%
%TMPL:P{"%tmpl%"}%
%TMPL:END%
%TMPL:DEF{"default"}%
This is a default template.
%TMPL:END%
%TMPL:DEF{"special"}%
This is a special template.
%TMPL:END%
...
%TMPL:P{"conditional" tmpl="special"}%
Documentation:
Parameters to blocks
%TMPL:DEF%
and
%TMPL:P%
support simple parameters. For
example, given the definition
%TMPL:DEF{"x"}% x%P%z %TMPL:END%
then
%TMPL:P{"x" P="y"}%
will expand to
xyz
.
Default parameter values can be set in the definition:
%TMPL:DEF{"x" y="1"}% x%y%z %TMPL:END%
then
%TMPL:P{"x"}%
will expand to
x1z
.
[...]
Conditional expansion
Using context identifiers
[...]
Using parameters
The mechanism to pass parameters to blocks can be used to conditionally call different template blocks. For example:
%TMPL:DEF{"conditional" tmpl="default"}%
%TMPL:P{"%tmpl%"}%
%TMPL:END%
%TMPL:DEF{"default"}%
This is a default template.
%TMPL:END%
%TMPL:DEF{"special"}%
This is a special template.
%TMPL:END%
...
%TMPL:P{"conditional" tmpl="special"}%
--
ArthurClemens - 01 Jan 2012
Hi Arthur, assuming this isn't meant for 1.1.x
Re-worked the tests so that they would pass on Foswiki 1.1
--
PaulHarvey - 19 Jan 2012
Anyone know if this is ready for release?
--
GeorgeClark - 02 Jun 2014
No idea, didn't even know this was on the way. Is there a feature proposal for it?
--
MichaelDaum - 02 Jun 2014
I have reviewed the code and the change is quite trivial. I deem it release ready, as discussed at
ReleaseMeeting01x02_20140616
--
CrawfordCurrie - 17 Jun 2014