You are here: Foswiki>Tasks Web>Item11400 (05 Jul 2015, GeorgeClark)Edit Attach

Item11400: Add default param values to TMPL:DEF.

pencil
Priority: Enhancement
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component:
Branches: trunk
Reported By: ArthurClemens
Waiting For:
Last Change By: GeorgeClark
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

 
Topic revision: r20 - 05 Jul 2015, GeorgeClark - This page was cached on 29 Aug 2016 - 04:13.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License