This question about Not sure...: Answered

How to implement 'optional' parameters for preference settings?

I'm trying to use something like the following
   * Set cite = <cite%IF{"$id=''" then="" else=' id="%id%"'}%%IF{"$conref=''" then="" else=' conref="%conref%"'}%%IF{"$conrefend=''" then="" else=' conrefend="%conrefend%"'}%%IF{"$conaction=''" then="" else=' conaction="%conaction%"'}%%IF{"$conkeyref=''" then="" else=' conkeyref="%conkeyref%"'}%>
   * Set zcite = </cite>
to be able to type something like this:
%cite{id="17" conref="23"}%Citation text 17%zcite%
%cite{id="23" conaction="mark"}%Citation text 23%zcite%
to get
<cite id="17" conref="23">Citation text 17</cite>
<cite id="23" conaction="mark">Citation text 23</cite>
but I get

<cite id="17" conref="23" conrefend="%conrefend%" conaction="%conaction%" conkeyref="%conkeyref%">Citation text 17</cite>
<cite id="23" conref="%conref%" conrefend="%conrefend%" conaction="mark" conkeyref="%conkeyref%">Citation text 23</cite>

Is there any possibility to implement such optional parameters via clever preference settings?

-- FranzJosefGigler - 13 Mar 2013

Here's what I would have expected to work - somehow -
   * Set element = &lt;element%IF{"defined attributeone" then=' attribute1="%attributeone%"' else=""'}%%IF{"defined attributetwo" then=' attribute2="%attributetwo%"' else=""}%%IF{"defined attributethree" then=' attribute3="%attributethree%"' else=""'}%&gt;
   * Set zelement = &lt;/element&gt;
but it doesn't.
%element{attributeone="value1" attributetwo="value2"}%
should return
<element attribute1="value1" attribute2="value2">
but I get

<element>

Do I really have to use URLPARAM constructs in some combination with INCLUDE to get this correct?

-- FranzJosefGigler - 14 Mar 2013

Now I've get a working version, I think, allthough it's somewhat ugly.

   * Set xmlelement = &lt;xmlelement%IF{"defined xmlattribute1" then='  attribute1="%xmlattribute1%"' else=""}%%IF{"defined xmlattribute2" then='  attribute2="%xmlattribute2%"' else=""}%%IF{"defined xmlattribute3" then='  attribute3="%xmlattribute3%"' else=""}%&gt;
   * Set zxmlelement = &lt;/xmlelement&gt;

%STARTSECTION{"xmlelement"}%%xmlelement{xmlattribute1="%xmlattribute1%" xmlattribute2="%xmlattribute2%" xmlattribute3="%xmlattribute3%"}%%ENDSECTION{"xmlelement"}%
Using
%INCLUDE{"%TOPIC%" section="xmlelement" xmlattribute2="value2" xmlattribute1="value3"}%Some element content.%zxmlelement%
gives the desired

<xmlelement attribute1="value3" attribute2="value2">Some element content.</xmlelement>

But there must be an easier and cleaner way.

-- FranzJosefGigler - 14 Mar 2013

 

QuestionForm edit

Subject Not sure...
Extension
Version Foswiki 1.1.8
Status Answered
Related Topics
Topic revision: r3 - 14 Mar 2013, FranzJosefGigler - This page was cached on 16 Oct 2018 - 23:29.

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