Hi James,
your how to looks good, but I can't picture a use for this… Could you give a problem situation where this would be the solution?
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
Tag cloud: (all tags)
Posted by GoVegan on 18 Mar 2010 23:45, last edited by GoVegan on 09 May 2010 06:06
Through understanding how the Wikidot engine processes includes, we are able to create highly sophisticated elements of code:
This is difficult to grasp at first, so lets put this into practice.
{$varA} {$varB} {$varC}
Our Page:
[[include inc:advanced
|varA=Banana
|varB=Split
]]
So the first thing that the Wikidot engine will do is import the page inc:advanced then assign values to the Variables, in the order of left-to-right, top-to-bottom.
Step | Rendered Code |
Import inc:advanced |
{$varA} {$varB} {$varC} |
|varA=Banana |
Banana {$varB} {$varC} |
|varB=Split |
Banana Split {$varC} |
Now lets see what happens if we place everything on one line:
Our Page:
[[include inc:advanced |varA=Banana |varB=Split]]
Step | Rendered Code |
Import inc:advanced |
{$varA} {$varB} {$varC} |
|varA=Banana |
Banana {$varB} {$varC} |
|varB=Split |
Banana Split {$varC} |
The same results.
Because of the way the Wikidot engine processes includes, we can actually create our own Temporary Variables within the include code:
Our Page:
[[include inc:advanced
|varA=Banana
|varB={$varTemp}
|varTemp=Split
]]
Step | Rendered Code |
Import inc:advanced |
{$varA} {$varB} {$varC} |
|varA=Banana |
Banana {$varB} {$varC} |
|varB={$varTemp} |
Banana {$varTemp} {$varC} |
|varTemp=Split |
Banana Split {$varC} |
This works because the includes are processed from left-to-right, top-to-bottom, and each variable is replaced in the page before the next variable is processed.
Therefore, the order in which we place our code is VERY important. For example, if we swapped the last two lines around:
Our Page:
[[include inc:advanced
|varA=Banana
|varTemp=Split
|varB={$varTemp}
]]
Step | Rendered Code |
Import inc:advanced |
{$varA} {$varB} {$varC} |
|varA=Banana |
Banana {$varB} {$varC} |
|varTemp=Split |
Banana {$varB} {$varC}1 |
|varB={$varTemp} |
Banana {$varTemp} {$varC} |
As you can see, by changing the ordering of our code, we have changed the way our Include Variables are assigned.
We can also reuse variables in this manner:
Our Page:
[[include inc:advanced
|varA={$varTemp}
|varTemp=Go
|varB={$varTemp}
|varTemp=Bananas
]]
Step | Rendered Code |
Import inc:advanced |
{$varA} {$varB} {$varC} |
|varA={$varTemp} |
{$varTemp} {$varB} {$varC} |
|varTemp=Go |
Go {$varB} {$varC} |
|varB={$varTemp} |
Go {$varTemp} {$varC} |
|varTemp=Bananas |
Go Bananas {$varC} |
Through using two includes, we are able to use the value of one variable to set the value of another.
[[include inc:advanced
|varA={$varA} |varB={$varB} |{$varTemp}=**James!**
]]
Our Page:
[[include inc:advanced-2
|varA=Go
|varB=Bananas
|varTemp=varC
]]
Step | Rendered Code |
Import inc:advanced-2 |
[[include inc:advanced |varA={$varA} |varB={$varB} |{$varTemp}=**James!**]] |
|varA=Go |
[[include inc:advanced |varA=Go |varB={$varB} |{$varTemp}=**James!**]] |
|varB=Bananas |
[[include inc:advanced |varA=Go |varB=Bananas |{$varTemp}=**James!**]] |
|varTemp=varC |
[[include inc:advanced |varA=Go |varB=Bananas |varC=**James!**]] |
Step | Rendered Code |
Import inc:advanced |
{$varA} {$varB} {$varC} |
|varA=Go |
Go {$varB} {$varC} |
|varB=Bananas |
Go Bananas {$varC} |
|varC=**James!** |
Go Bananas **James!** |
Go Bananas James! |
We can even build variable names from separate parts.
inc:advanced-3:
{${$varA}{$varD}
{$varB}Apples}
{$Eat{$varC}}
Our Page:
[[include inc:advanced-3 |varA=Go |varB={$Buy |varC=Bananas |varD=Potty} |EatBananas=Eating Bananas ]]
Step | Rendered Code |
Import inc:advanced-3 |
{${$varA}{$varD} |
|varA=Go |
{$Go{$varD} |
|varB={$Buy |
{$Go{$varD} |
|varC=Bananas |
{$Go{$varD} |
|varD=Potty} |
{$GoPotty} |
|EatBananas=Eating Bananas |
{$GoPotty} |
Setting a variable doesn't change variables within the include code. Therefore, if we attempted the following code:
Our Page:
[[include inc:advanced
|varA=Go
|varB=Bananas
|varTemp=varC
|{$varTemp}=James!
]]
Step | Rendered Code |
Import inc:advanced |
{$varA} {$varB} {$varC} |
|varA=Go |
Go {$varB} {$varC} |
|varB=Bananas |
Go Bananas {$varC} |
|varTemp=varC |
Go Bananas {$varC}2 |
|{$varTemp}=James! |
Go Bananas {$varC}3 |
What we wanted to happen is for {$varTemp} to become varC, so that |varC=James!.
This doesn't work, because [[include]]:
Replaces Variables in the included page only, according to the the definitions in the [[include]] block
James Kanjo. Please visit his/her userPage.
rurwin does not match any existing user name. Please visit his/her userPage.
Hi James,
your how to looks good, but I can't picture a use for this… Could you give a problem situation where this would be the solution?
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
The Calendar Application uses this.
It's used for the Notebook Application as well, specifically for determining the type of note wanted.
Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me
James and Richard,
Thanks for putting in the time to unravel this and document it for the rest of us. It's a well written explanation. :-)
Sue
You're welcome :-)
I'm so glad it was able to help you learn something!
Okay, I've been avoiding this conversation and planning to read it when everything's been worked out… if the page is pretty much completed now (?) I'll have another read.
Thanks James Kanjo, rurwin does not match any existing user name and Timothy Foster.
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server | NEW: Wikiroo, backup tool (in development)
I see conflict… with this howto, and Erich's HowTo Include with Defaults.
Discuss?
Hmm, I never saw that.
Well, it doesn't hurt to it in more than one place. Plus, this page kind of conglomerates a bunch of different aspects on one page, so as long as it is introduced, a link can be produced to the detailed page, since defaults can be trickier. And lastly, this page explains how it works, somewhat, not only what to do.
Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me
“Conflict”… I think I used the wrong word. I really meant “duplication”.
But you're right! As Scott says: “Yours fleshes out the thinking behind it”, whether Erich's just gives instructions on what to do.
Thanks for the addition, btw, though you forgot to add yourself as an author of the page.
On second thought, I don't think that your contribution belongs to this page… So I've created a new HowTo for you:
Wikidot Include Techniques
I did this because the guide for experts is more of a “reference manual” to explain the basic behaviour of Wikidot Includes.
Including with defaults is, as you say, a conglomeration of the guide. It takes the information, and puts it directly into practical use. And that's what I want the techniques page to be: A compilation of advanced include techniques, each unifying what the guide teaches.
I have a couple of advanced techniques to share, and if I added them to the Experts guide, then the guide would become way too long to read through. This splits it up a bit and allows for more contributions.
I can see how this works. More pages helps organize the material, concentrate it, and allows for expansion of the material.
Now I'm curious ;)
Timothy Foster - @tfAuroratide
Auroratide.com - Go here if you're nerdy like me
Conflict, or overlap? I agree with Timothy. Both work well for me. Erich's directly addresses a key functionality. Yours fleshes out the thinking behind it.
Wow, this is really detailed. And interesting.
Michał Frąckowiak @ Wikidot Inc.
Visit my blog at michalf.me