Wikidot Includes: For Beginners

Posted by GoVegan on 18 Mar 2010 23:43, last edited by GoVegan on 09 May 2010 06:06

Tags: include variable

rating: +10+x

Wikidot provides you with the ability to import another page's source code into your current page, and change variables within it. You can even include pages from other wikis1. This becomes very useful when you are re-inserting very similar code on multiple pages.

For instance, if you are wanting to create a small information table on many pages, you might use the following code:

[[div style="float: left;"]]
||~ Name || Gold ||
||~ Type || Mineral ||
||~ Colour || Yellow ||
||~ SLC || Solid ||
||~ Shiny || Yes ||
[[/div]]

Which renders this floating table:

Name Gold
Type Mineral
Colour Yellow
SLC2 Solid
Shiny Yes









But having to type in all of that code on so many pages… it's a lot of typing. Also, and more importantly, if you decide to get rid of the “Shiny” section in the future, it would be a nightmare to go to all of your pages and remove the “Shiny” code.
This is why includes are useful, because you can create a single “master page” that controls everything that uses it.

So let's create a page called inc:info-table, and on it, we will have the following code:

[[div style="float: left;"]]
||~ Name || {$name} ||
||~ Type || {$type} ||
||~ Colour || {$colour} ||
||~ SLC || {$slc} ||
||~ Shiny || {$shiny} ||
[[/div]]

Take note of the funny words surrounded with curly brackets and a dollar symbol. These are called Include Variables. The word that follows the dollar symbol is the name you assign to the variable: {$variable-name}
Variables are dynamic, meaning that they can change depending on what you want them to be. If I want the variable {$name} to change to the word “Gold”, then all I need to do is to include the inc:info-table page, and type in |name=Gold.

Let's put this into practice on our wiki pages. If we want to use the information table, all we need to do is paste the following code:

[[include inc:info-table |name=Gold |type=Mineral |colour=Yellow |slc=Solid |shiny=Yes]]

This will render:

Name Gold
Type Mineral
Colour Yellow
SLC Solid
Shiny Yes









It's that easy.

Variable Limitations

Now that you know how to create Wikidot Includes, it is important to know that there are limitations to the variable names you can use.

Acceptable variable names may contain some or all of the following:

  • Alphabetical characters (using the basic English alphabet only)
  • Numerical characters (all digits from 0 to 9)
  • Hyphens (the “-” character)
  • Underscores (the “_” character)

Wikidot Include Variables are case-sensitive. So the variable {$shiny} is a completely different variable to {$Shiny}.

Related Articles

Author

James KanjoJames Kanjo. Please visit his/her userPage.


Related articles

Comments

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.