If, Then, Else Conditionals
Forum » Help / Editing pages » If, Then, Else Conditionals
started by: James KanjoJames Kanjo
on: 1210231378|%e %b %Y, %H:%M %Z|agohover
number of posts: 7
rss icon RSS: new posts
summary:
Do such conditionals as IF this DO THAT, and OTHERWISE DO THIS exist within Wikidot.com?
If, Then, Else Conditionals
James KanjoJames Kanjo 1210231379|%e %b %Y, %H:%M %Z|agohover

Do such conditionals as IF this DO THAT, and OTHERWISE DO THIS exist within Wikidot.com?

What I'm essentially trying to do is create a template. I read the How To Create Templates page, and looked at the http://siliconcity.wikidot.com/HeroBox page.

Apparently, I could use the [include templatename] feature with a template as such (as they have done on the http://siliconcity.wikidot.com/template:herocharacter page. However, I would prefer that instead of setting unused variables to "Not mentioned", I think it would be ideal to have an If command within the template I'm including.

Something like this: [Include template |IF {name} exists, display {name} ELSE don't display anything]

Does anybody know if something like this is possible?

Cheers ~ James Kanjo

unfold If, Then, Else Conditionals by James KanjoJames Kanjo, 1210231379|%e %b %Y, %H:%M %Z|agohover
Re: If, Then, Else Conditionals
ErichSteinboeckErichSteinboeck 1210236020|%e %b %Y, %H:%M %Z|agohover

With the ideas described in Include Part Of A Page Only (Tricky Version) you should be able set up an include template that will

  • show an attribute if “attribute=some-attribute-text” is specified, or
  • does not display anything if “attributeSpecified=@@” is specified.

Something like:

[[include Template
|name=Name
|playerSpecified=@@
|originSpecified=@@
|level=3
.
.
|footnotesSpecified=@@
]]
unfold Re: If, Then, Else Conditionals by ErichSteinboeckErichSteinboeck, 1210236020|%e %b %Y, %H:%M %Z|agohover
Re: If, Then, Else Conditionals
James KanjoJames Kanjo 1210240502|%e %b %Y, %H:%M %Z|agohover

Thankyou for that, but it isn't exactly helpful to my situation. You see, If I do that, then the heading would still display. Imagine the template looked like this:

**Name:** {$name}
**Age:** {$age}
**Sex:** {$sex}

If I included that on a page with code like this:

[[include Template
|name=James Kanjo
|age=@@
|sex=@@
]]

Then it would display the following:

Name: James Kanjo
Age:
Sex:

But if the values equal nothing, I don't want the text for that value to display, so I want this to display instead if the same values are used:

Name: James Kanjo

Does that make sense? So the code on the template page could be something like this:

If {$name} Then Display="**Name:** {$name}"|Else Display=""
If {$age} Then Display="**Age:** {$age}"|Else Display=""
If {$sex} Then Display="**Sex:** {$sex}"|Else Display=""

So if the values exist, then display the preceding text. Now, is that a possibility?

By the way, your "include part of a page on another page" worked perfectly for me! Thankyou for helping me back then - especially when everybody else thought it was impossible. I said it back then and I will say it again: you showed them!

Cheers ~ James Kanjo

unfold Re: If, Then, Else Conditionals by James KanjoJames Kanjo, 1210240502|%e %b %Y, %H:%M %Z|agohover
Re: If, Then, Else Conditionals
Helmuti_pdorfHelmuti_pdorf 1210243124|%e %b %Y, %H:%M %Z|agohover

My proposal would be:
1. the included Template without any labels:

{$name}
{$age}
{$sex}

2. the individual page including the template - put the labels in the variables!
[[include incl-Template
|name=James Kanjo
|age=@@
|sex=@@
]]

[[include incl-Template
|name=**Name:** James Kanjo
|age=@@
|sex=@@
]]

Gives:

James Kanjo
Name: James Kanjo

and nothing else…

unfold Re: If, Then, Else Conditionals by Helmuti_pdorfHelmuti_pdorf, 1210243124|%e %b %Y, %H:%M %Z|agohover
Re: If, Then, Else Conditionals
ErichSteinboeckErichSteinboeck 1210251282|%e %b %Y, %H:%M %Z|agohover

if the values equal nothing, I don't want the text for that value to display

I understand what you mean. As Wikidot does not support an IF/THEN/ELSE constructs, I suggested to use the idea that is presented in [[Part Of A Page Only (Tricky Version)].

So, your template should e. g. look like:

[[table]]
[[row]]
[[cell]][!--{$nameSpecified}--][[[@@|]]]**Name:**[[/cell]]
[[cell]]{$name}[[/cell]]
[[/row]]
[[row]]
[[cell]][!-- --][!--{$playerSpecified}--][[[@@|]]]**Player:**[[/cell]]
[[cell]]{$player}[[/cell]]
[[/row]]
[[row]]
[[cell]][!-- --][!--{$originSpecified}--][[[@@|]]]**Origin:**[[/cell]]
[[cell]]{$origin}[[/cell]]
[[/row]]
[[row]]
[[cell]][!-- --][!--{$levelSpecified}--][[[@@|]]]**Level:**[[/cell]]
[[cell]]{$level}[[/cell]]
[[/row]]
[[row]]
[[cell]][!-- --][!--{$footnotesSpecified}--][[[@@|]]]**Footnotes:**[[/cell]]
[[cell]]{$footnotes}[!-- --][[/cell]]
[[/row]]
[[/table]]

I know, it's not very readable, and you have to carefully place the “markers” inside the table (it should be more straightforward, if you do not have to use a table.)

And your include should look like:

[[include Template
|name=Name
|playerSpecified=@@
|originSpecified=@@
|level=3
|footnotesSpecified=@@
]]

Then the result would be:

Name: Name
Level: 3
unfold Re: If, Then, Else Conditionals by ErichSteinboeckErichSteinboeck, 1210251282|%e %b %Y, %H:%M %Z|agohover
Re: If, Then, Else Conditionals
James KanjoJames Kanjo 1210336573|%e %b %Y, %H:%M %Z|agohover

ErichSteinboeck, you bloody beauty! You've done it again!

I made a change, however; I found the same results by removing the word "Specified" from everywhere, which is more convenient than having a separate variable to say if it doesn't exist. Unless you have a reason to stop me from doing this (such as, if I get rid of the word "Specified" I will cause problems later).

It seems your clever technique is a double edged sword!

Cheers ~ James Kanjo

unfold Re: If, Then, Else Conditionals by James KanjoJames Kanjo, 1210336573|%e %b %Y, %H:%M %Z|agohover
Re: If, Then, Else Conditionals
ErichSteinboeckErichSteinboeck 1210339075|%e %b %Y, %H:%M %Z|agohover

same results by removing the word "Specified" from everywhere

Brilliant idea! I'll adapt the Howto to reflect this!

Please also see my Community Howto Set Up An Infobox that shows how to display only attributes with a value — all other values are not shown.

Depending on your setup, this may be better because you can later change the include template without breaking all existing includes. In your current setup you'd have to adapt all existing includes.

unfold Re: If, Then, Else Conditionals by ErichSteinboeckErichSteinboeck, 1210339075|%e %b %Y, %H:%M %Z|agohover
new post
Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.