Quantcast
Viewing all articles
Browse latest Browse all 18

Wikidot Include Techniques

This guide complements the two HowTos: Wikidot Includes for Beginners and Wikidot Includes for Experts.

Here we will show you how advanced include techniques can be used to automate tasks and create frameworks for Wikidot programs.

Default Values

With the utilization of two include pages, one can allow certain variables to retain default values if they are not defined. Recall in the very first example what happened whenever varC wasn't defined:

Our Page:

 [[include inc:advanced |varA=Banana |varB=Split ]] 

The result is the following:
Banana Split {$varC}

Notice how we get an ugly variable in the expressed page since we didn't define what it was. So, let's say that rather than having this weird variable show up, we want for **James!** (which renders as James!) to replace the varC if it isn't defined by the user. However, if defined, we want the defined version to appear in precedence.

This is fortunately possible with the aid of two includes. For this, we will use the typical inc:advanced plus a new page called inc:advanced-4 with the following on it:

 [[include inc:advanced |varA={$varA} |varB={$varB} |varC={$varC} |varC=**James!** ]] 

Now we will use the above original include without varC clearly defined and track what is happening:

Step Rendered Code
Import inc:advanced-4 [[include inc:advanced |varA={$varA} |varB={$varB} |varC={$varC} |varC=**James!**]]
|varA=Banana [[include inc:advanced |varA=Banana |varB={$varB} |varC={$varC} |varC=**James!**]]
|varB=Split, [[include inc:advanced |varA=Banana |varB=Split, |varC={$varC} |varC=**James!**]]
Step Rendered Code
Import inc:advanced {$varA} {$varB} {$varC}
|varA=Banana Banana {$varB} {$varC}
|varB=Split, Banana Split, {$varC}
|varC={$varC} Banana Split, {$varC}
|varC=**James!** Banana Split, James!

And behold, we didn't define varC yet James! appears! But what if we wanted to define varC as "yum!"?

We'll examine this code:

 [[include inc:advanced-4 |varA=Banana |varB=Split, |varC=yum! ]] 
Step Rendered Code
Import inc:advanced-4 [[include inc:advanced |varA={$varA} |varB={$varB} |varC={$varC} |varC=**James!**]]
|varA=Banana [[include inc:advanced |varA=Banana |varB={$varB} |varC={$varC} |varC=**James!**]]
|varB=Split, [[include inc:advanced |varA=Banana |varB=Split, |varC={$varC} |varC=**James!**]]
|varC=yum! [[include inc:advanced |varA=Banana |varB=Split, |varC=yum! |varC=**James!**]]
Step Rendered Code
Import inc:advanced {$varA} {$varB} {$varC}
|varA=Banana Banana {$varB} {$varC}
|varB=Split, Banana Split, {$varC}
|varC=yum! Banana Split, yum!
|varC=**James!** Banana Split, yum!

Since the code is rendered top to bottom. left to right and variables are replaced before the next is processed, varC=**James!** wasn't able to replace a varC since it didn't exist after it was defined. The final note to make is that you can set default values for the other variables as well if wished.

For a simplified guide to default values, see Include with Defaults.

Related Articles

Authors

Image may be NSFW.
Clik here to view.
James Kanjo
James Kanjo
. Please visit his/her userPage.

Image may be NSFW.
Clik here to view.
Timothy Foster
Timothy Foster
. Please visit his/her userPage.

by Image may be NSFW.
Clik here to view.
James Kanjo
James Kanjo


Viewing all articles
Browse latest Browse all 18

Trending Articles